Jan 30, 2022

Check Alphabet Vowel or Consonant - Java Program Example

Here we can see a java program for check any entered alphabet number is vowel or Consonant. When we compile this java program then compiler take an input as alphabet and check entered alphabet is vowel or Consonant.




Program Code

package com.androidpro.in;

import
java.io.BufferedReader;
import
java.io.IOException;
import
java.io.InputStreamReader;
import
java.io.PrintStream;
import
java.text.ParseException;
import
java.text.SimpleDateFormat;
import
java.util.Date;
import
java.util.Scanner;

public class
Main {
   
public static void main(String[] arg) {
        System.
out.println("Enter An Alphabet For \n Check Vavel And Consuntant");
        boolean
isVowel = false;
        ;
       
Scanner scanner = new Scanner(System.in);
       
System.out.println(" ");
        char
chr = scanner.next().charAt(0);
       
scanner.close();
        switch
(chr) {
           
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("Character " + chr + " is a Vowel.");
       
} else {
           
if ((chr >= 'a' && chr <= 'z') || (chr >= 'A' && chr <= 'Z'))
                System.
out.println("Character " + chr + " is a Consonant.");
            else
               
System.out.println("Input is not an alphabet, please enter valid character.");
       
}


    }
}

  

Output


Enter An Alphabet For
 Check Vavel And Consuntant

a
Character a is a Vowel.

Enter An Alphabet For

Check Vavel And Consuntant

t

Character t is a Consonant.



Share:

0 Comments: