Java program to check vowel or consonant
belongs to collection: Simple Formula Based Java Programs
All Answers
need an explanation for this answer? contact us directly to get an explanation for this answer
In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..
import java.util.Scanner;
class Char
{
public static void main(String[ ] arg)
{
int i=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a character : ");
char ch=sc.next( ).charAt(0);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
{
System.out.println("Entered character "+ch+" is Vowel");
}
else if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
System.out.println("Entered character "+ch+" is Consonant");
else
System.out.println("Not an alphabet");
}
}
Result:
Enter a character :
o
Entered character o is Vowel
need an explanation for this answer? contact us directly to get an explanation for this answertotal answers (2)
answer using switch statement
need an explanation for this answer? contact us directly to get an explanation for this answer