Dremendo Tag Line

Input alphabet check vowel or not using switch case in Java

switch case - Question 2

In this question, we will see how to input an alphabet in lowercase and check if it is a vowel or not in Java programming using the switch case statement. To know more about switch case statement click on the switch case statement lesson.

Q2) Write a program in Java to input an alphabet in lowercase and check if it is a vowel or not using the switch case statement.

Program

import java.util.Scanner;

public class Q2
{
    public static void main(String args[])
    {
        char c;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter an alphabet in lowercase ");
        c=sc.nextLine().charAt(0);
        switch(c)
        {
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
                System.out.print("Vowel");
                break;

            default:
                System.out.print("Not a vowel");
        }
    }
}

Output

Enter an alphabet in lowercase i
Vowel
video-poster