Java program to check whether an alphabet is vowel or consonant

Write a java program to check whether an alphabet is vowel or consonant

In this program, java program to identify whether the given character is a vowel or not using if else statement. Whit the help of the below program, you will get to know how to write and print whether the given number is a vowel.

What are the Vowels?

A: def: A speech sound which is produced with the vibration of vocal chords without audible friction, which is being blocked by teeth, tongue or lips :P. We know that there are five vowels: a, e, i, o, u or A, I, E, O, U.

What are the consonants?

Apart from A, E, I, O, U rest of the alphabets are consonants. That's it.
Basically, we can write the code in two different ways, using if statement or if-else statements or java switch case statement.

Here, o is stored in a char variable ch. In java, you use double quotes (" ") for strings and single quotes (" ") for characters.

Now, to check whether ch is vowel or not, we check if ch is any of: (a, e, i, o, u). This is done using a simple if...else statement.

We can also check for vowel or consonant using a switch statement in java.

  • Program:

public class VowelConsonant {

    public static void main(String[] args) {

        char ch = 'o';

        if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' )
            System.out.println(ch + " is vowel");
        else
            System.out.println(ch + " is consonant");

    }
}                                     

  • Output:

o is vowel

  • Visit:

Java program to print an Integer Here
Java program to add two integers Here
Java program to find ASCII value of a character Here
Java program to compute quotient and remainder Here
Java program to swap two numbers Here
Java program to check whether a given number is even or odd Here

0 comments