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.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Vowel_Consonant
{
public static void main(String[] args) throws Exception
{
char n;
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the character you want to check:");
n = (char) bf.read();
switch(n)
{
case 'a':
System.out.println("The given character "+n+" is vowel");
break;
case 'e':
System.out.println("The given character "+n+" is vowel");
break;
case 'i':
System.out.println("The given character "+n+" is vowel");
break;
case 'o':
System.out.println("The given character "+n+" is vowel");
break;
case 'u':
System.out.println("The given character "+n+" is vowel");
break;
default:
System.out.println("The given character "+n+" is consonant");
break;
}
}
}
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
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Apply for Java Internship
- Practice BCA MCQs
- Practice Programming MCQs
- Apply for Computer Science Internship
- Practice Information Technology MCQs