Java Tutorial
In java programming, this program is used to find the character is vowel or consonent using switch statement.
import java.io.*; class VowelsTest { public static void main(String args[]) throws IOException{ char ch; // Gets input character DataInputStream in= new DataInputStream(System.in); System.out.println("Check character is vowel or not"); System.out.println("--------------------------------"); System.out.print("Enter character: "); ch = (char)in.read(); // checks character is vowel or not switch(ch) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': System.out.println("Input character '"+ch+"' is a vowel!"); break; default: System.out.println("Input character '"+ch+"' is a consonent!"); } } }Output:
D:\Java_Programs>javac VowelsTest.java D:\Java_Programs>java VowelsTest Check character is vowel or not -------------------------------- Enter character: a Input character 'a' is a vowel! D:\Java_Programs>java VowelsTest Check character is vowel or not -------------------------------- Enter character: r Input character 'r' is a consonent!
Java Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page