Java Program to Check if the Given Character is Vowel or Consonant - The Coding Shala

Home >> Java Programs >> Check Character is Vowel or Consonant

 In this post, we will learn how to Check Whether the Character is Vowel or Consonant in Java.

Java Program to Check if the Given Character is Vowel or Consonant

As we know, Vowels are ('a', 'e', 'i', 'o', 'u'), and all the other characters are consonant. Write a Java Program to check if the given character is vowel or consonant.

Example 1:
Input: e
Output: Vowel

Java Program: 

// Java program to Check Vowel or Consonant

import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) { 
		
		Scanner sc = new Scanner(System.in);
		
		// take input char
		System.out.println("Enter the Character between a to z");
		// next will take input as string so charAt(0) used
		char ch = sc.next().charAt(0);  
		
		if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
			System.out.println("It is a Vowel");
		} else {
			System.out.println("It is a Consonant");
		}
		
		sc.close();
	}
}

Output: 

Enter the Character between a to z
r
It is a Consonant


Other Posts You May Like
Please leave a comment below if you like this post or found some errors, it will help me to improve my content.

Comments

Popular Posts from this Blog

Shell Script to Create a Simple Calculator - The Coding Shala

N-th Tribonacci Number Solution - The Coding Shala

Java Program to Convert Binary to Decimal - The Coding Shala

LeetCode - Shuffle the Array Solution - The Coding Shala

Java Program to Find GCD or HCF of Two Numbers - The Coding Shala