Java Program to Check Whether an Alphabet is Vowel or Consonant

In the following example Java program to check whether an alphabet is a vowel or a consonant :
Program :
import java.util.Scanner;

public class VowelConsonant {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter an alphabet: ");
        char ch = scanner.next().charAt(0);

        if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
            ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
            System.out.println(ch + " is a vowel.");
        } else {
            System.out.println(ch + " is a consonant.");
        }
    }
}
Output :
Enter an alphabet: e
e is a vowel.
Enter an alphabet: h
h is a consonant.
In this program, we use the Scanner class to read an alphabet input by the user. We then check whether the alphabet is a vowel or a consonant using an if statement.

If the alphabet is one of the five vowels (lowercase or uppercase), we print out a message indicating that the alphabet is a vowel. Otherwise, we print out a message indicating that the alphabet is a consonant.