In this program, you'll learn to check whether an alphabet is a vowel or a consotant using if..else and switch statement in Java.
Program:
import java.util.*;
public class Vowel_Consonant
{
public static void main(String[] args)
{
char ch;
Scanner sc=new Scanner(System.in);
System.out.println("Input any word: ");
ch=sc.next().charAt(0);
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:
Input any word:
a
a is vowel
Input any word:
x
x is consonant