Java Program to Check Whether a Character is a Vowel, Consonant or Digit

This is a Java Program to Check if a Given Character is Vowel or Consonant.

Enter any character as an input. Now we match this character with the already defined vowels in switch case. If the given character matches with any of the vowels then output generated is vowel or else consonant as in a default case.

Here is the source code of the Java Program to Check if a Given Character is Vowel or Consonant. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.Scanner;
  5. public class Vowel_Consonant 
  6. {
  7.     public static void main(String[] args) throws Exception 
  8.     {
  9.         char n;
  10.         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  11.         System.out.print("Enter the character you want to check:");
  12.         n = (char) bf.read();
  13.         switch(n)
  14.         {
  15.             case 'a':
  16.             System.out.println("The given character "+n+" is vowel");
  17.             break;
  18.  
  19.             case 'e':
  20.             System.out.println("The given character "+n+" is vowel");
  21.             break;
  22.  
  23.             case 'i':
  24.             System.out.println("The given character "+n+" is vowel");
  25.             break;
  26.  
  27.             case 'o':
  28.             System.out.println("The given character "+n+" is vowel");
  29.             break;
  30.  
  31.             case 'u':
  32.             System.out.println("The given character "+n+" is vowel");
  33.             break;
  34.  
  35.             default:
  36.             System.out.println("The given character "+n+" is consonant");
  37.             break;
  38.         }
  39.     }
  40. }

Output:

$ javac Vowel_Consonant.java
$ java Vowel_Consonant
 
Enter the character you want to check:b
The given character b is consonant

Sanfoundry Global Education & Learning Series –- 1000 Java Programs.

advertisement
advertisement

Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.