Write a java program to check whether the given character is vowel or not
Answers
Answer:
In Java, you use double quotes (" ") for strings and single quotes (' ') for characters. Now, to check whether ch is vowel or not, we check if ch is any of: ('a', 'e', 'i', 'o', 'u') . This is done using a simple if..else statement. We can also check for vowel or consonant using a switch statement in Java.
Answer:
import java.util.Scanner;
public class JavaProgram
{
public static void main(String args[])
{
char ch;
Scanner scan = new Scanner(System.in);
System.out.print("Enter an Alphabet : ");
ch = scan.next().charAt(0);
if(ch=='a' || ch=='A' || ch=='e' || ch=='E' ||
ch=='i' || ch=='I' || ch=='o' || ch=='O' ||
ch=='u' || ch=='U')
{
System.out.print("This is a Vowel");
}
else
{
System.out.print("This is not a Vowel");
}
}
}