Write a program to input any alphabet and check whether it is vowel or consonant


The program is a Java program that takes a character input from the user and checks whether it is a vowel or a consonant.

  • The program starts by importing the java.util.Scanner package which allows user input to be taken from the console.
  • In the main method, the program prompts the user to enter a character using the System.out.print method and reads the input using the Scanner object's next() method.
  • The program then checks whether the character is a vowel or consonant using an if statement. The condition of the if statement checks if the entered character is equal to any of the vowels 'a', 'e', 'i', 'o', or 'u' in both lowercase and uppercase. If the condition is true, the program prints "This is a Vowel". Otherwise, the program prints "This is a Consonant" using the System.out.println() method.
  • The program then exits the main method, and the program execution ends.

Source Code

import java.util.Scanner;
class Vowel_Consonant
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		System.out.print("Enter the Character :");
		char ch = input.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("This is a Vowel");
		}
		else
		{
			System.out.println("This is a Consonant");
		}
	}
}

Output

Enter the Character :O
This is a Vowel

Example Programs