TutorialStudyMite

Java Program to check vowel or consonant using switch case

Beginner friendly

Track completion, mastery, and revision.

In the following question, we are supposed to ask the user for character input and check if the input is a vowel or not using Switch Case construct.

Algorithm:

  1. Accept and store user input.
  2. Make a copy of the input and store it.
  3. Convert the copy to uppercase for easier comparison and uniformity.
  4. Use a switch-case construct to check for vowels.
  5. Print the result based on the vowel check.
/* Program to check if entered character is vowel or not using Switch Case */

import java.util.Scanner;

class SwitchVowel {
    public static void main() {
        Scanner inp = new Scanner(System.in);
        System.out.print("\nEnter Character: ");
        char c = (inp.nextLine()).charAt(0);
        char z = Character.toUpperCase(c); // Changing Value to UpperCase for uniformity.

        switch (z) { // Checking Vowel Character using Switch Case
            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 Non-Vowel Character.");
        }
    }
}

Output:

Enter Character: X
X is a Non-Vowel Character.

 Enter Character: u
u is a Vowel.

 Enter Character: 5
5 is a Non-Vowel Character.

Finished reading?

Was this helpful?

Your feedback shapes better tutorials for everyone.