Java program to find whether given character is vowel or consonant using switch case

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case. To verify whether given character is a vowel read a character from the user into a variable (say ch).

  • Define a boolean bool variable and initialize it with false.

  • Define cases for character ch with vowel characters, both capital and small ('a', 'e', 'i', 'o', 'u' ) without break statements.

  • For all these assigns make the bool variable true.

  • Finally, if the value of the bool variable is true given character is a vowel else consonant


import java.util.Scanner;
public class VowelOrConsonantSwitch {
   public static void main(String args[]) {
      boolean bool = false;
      System.out.println("Enter a character :");
      Scanner sc = new Scanner(;
      char ch =;
      switch(ch) {
         case 'A' :
         case 'E' :
         case 'I' :
         case 'O' :
         case 'U' :
         case 'a' :
         case 'e' :
         case 'i' :
         case 'o' :
         case 'u' : bool = true;
      if(bool == true){
         System.out.println("Given character is an vowel ");
         System.out.println("Given character is a consonant ");


Enter a character :
Given character is an vowel
Enter a character :
Given character is a consonant