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 find sum, product and average of given numbers - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

Add two numbers in Scala - The Coding Shala

LeetCode - Number of Good Pairs Solution - The Coding Shala

Richest Customer Wealth LeetCode Solution - The Coding Shala