Java Program To Check Whether An Alphabet Is Vowel or Consonant (If-Else & Switch-Case)
Java Program To Check Whether An Alphabet Is Vowel or Consonant (If-Else & Switch-Case)
char ch = 'i';
}
}
Output
i is vowel
In the above program, 'i' is stored in a char variable ch . In Java, you use double
quotes (" ") for strings and single quotes (' ') for characters.
We can also check for vowel or consonant using a switch statement in Java.
char ch = 'z';
switch (ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println(ch + " is vowel");
break;
default:
System.out.println(ch + " is consonant");
}
}
}
Output
z is consonant
If ch is either of cases: ('a', 'e', 'i', 'o', 'u') , vowel is printed. Else, default case
is executed and consonant is printed on the screen.