Here is a simple Java program to check whether a given letter is a vowel or a consonant.
β
Java Code:
π Example Output:
β
Explanation:
|
import java.io.*;
import java.util.*;
class Cal
{
public static void main(String[] args)
{
char c;
System.out.println(“Enter the character”);
Scanner s=new Scanner(System.in);
c=s.next().charAt(0);
switch(c)
{
case ‘a’:
case ‘e’:
case ‘i’:
case ‘o’:
case ‘u’:
case ‘A’:
case ‘E’:
case ‘I’:
case ‘O’:
case ‘U’:
System.out.println(c +”is a vowel”);
break;
default:
System.out.println(c +”is a Consonant”);
}
}
}
|
|
-
Converts the input letter to lowercase using Character.toLowerCase()
.
-
Checks whether the character is a valid English alphabet.
-
Then determines if it is a vowel (a, e, i, o, u
) or a consonant.