Check Vowel or Consonant using switch case in java

 problem statement:-Write A Program to check the alphabet is vowel or consonant using switch case.

vowel:- 'a','e','i','o','u','A','E','I','O','U'

consonant:-alphabet other than vowel  is consonant

Sourcecode

package strings;
import java.util.Scanner;
public class anagram {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("enter the character : ");
        char ch=sc.next().charAt(0);
        boolean isVowel=false;
        switch(ch) {
        case 'a' :
        case 'e' :
        case 'i' :
        case 'o' :
        case 'u' :
        case 'A' :
        case 'E' :
        case 'I' :
        case 'O' :
        case 'U' : isVowel =true;
        }
        if(isVowel==true) {
            System.out.println(ch+" is a vowel");
            
        }
        else {
            if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')) {
                System.out.println(ch+" is a consonant");
            }
            else {
                System.out.println("INPUT IS NOT AN ALPHABET");
            }
        }
    }
}
output:-

enter the character :
A
A is a vowel


Comments