2. Write a program in Java to check whether the input alphabet is a vowel or not.
Logic of the solution:
- Declare le of char type to store user input into it.
- Print a message for the user using
System.out.println and ask user for a letter
- Using charAt(0) to take the 1st letter only as input even if the user writes a word.
- Compare the letter in the variable using the conditional statements
- If the input is equal to any of the vowel, then it is a Vowel otherwise it is a Consonant
- Print Message accordingly
public static void main(String  arg)
Scanner sc = new Scanner(System.in);
System.out.println("Enter a Letter");
if(le=='a' || le=='e' || le=='i' || le=='o' || le=='u' || le=='A' || le=='E' || le=='I' || le=='O' || le=='U')
System.out.println(le+" is vowel");
System.out.println(le+" is not a vowel");
Alternative logics that can be applied:
As in previous question this one can also be done using an Array, here we will store the vowels as elements of the Array and compare them with the user input one by one using if statement.
Continue to next page for another question.