In this post, we will see how to check a Character is Vowel or Consonant.
You just need to check if character is part of set {a,A,e,E,i,I,o,O,u,U}.If it is part of set then it is Vowel else Consonant.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import java.util.Scanner; public class VowelFinder { public static void main(String args[]) { char character; Scanner sacnner = new Scanner(System.in); System.out.print("Enter an Alphabet : "); character = sacnner.next().charAt(0); if(character=='a' || character=='A' || character=='e' || character=='E' || character=='i' || character=='I' || character=='o' || character=='O' || character=='u' || character=='U'){ System.out.print(character+" is a Vowel"); }else{ System.out.print(character+ " is a Consonant"); } } } |
Output:
Enter an Alphabet : g
g is a Consonant
g is a Consonant
That’s all about Java Program to Check a Character is Vowel or Consonant.
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.