Java Program to check vowel or consonant using if-else

In the following problem, we are asked to write a Java source code where we are supposed to ask the user to enter a character using standard input and then check if the character is a vowel or not.

The algorithm will be:

  1. Enter and Store User Input.
  2. Create a duplicate of the original value in a different variable and change its case.
  3. Use an if-else construct.
  4. Compare input character with all the vowels (both in Lower Case and Upper Case).
  5. Print the result accordingly.

Note: You can use both Scanner and BufferedReader Class to take input.

Source Code:

/* Program to check if entered character is vowel or not using if-else*/
import java.util.*;
class CheckVowel
public static void main()
Scanner inp=new Scanner(;
System.out.print("\n Enter Character: ");
char c=((inp.nextLine()).charAt(0));
char z=Character.toUpperCase(c); //Changing Value to UpperCase for uniformity.

if(z=='A' || z=='E' || z=='I' || z=='O' || z=='U')    //Checking if Vowel
  System.out.println(c+" is a Vowel.");
   System.out.println(c+" is not a Vowel."); 


Enter Character: t
t is not a Vowel.

 Enter Character: V
V is not a Vowel.

 Enter Character: o
o is a Vowel.

 Enter Character: A
A is a Vowel.

Report Error/ Suggestion

Related Posts:

CopyRight © 2020

CopyRight © 2020