Java Program to Check if the Given Character is Vowel or Consonant - The Coding Shala
Home >> Java Programs >> Check Character is Vowel or Consonant
Other Posts You May Like
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
- Java Program to Add Two Numbers
- Java Program to Find the Sum of Digits of a Number
- Java Program to Swap Two Numbers
- How to take input numbers into Array in Java
- Java Program to Find the Sum of N numbers
Comments
Post a Comment