In this tutorial you will learn about the Java Program to check whether input character is vowel or consonant and its application with practical example.
In this tutorial, we will learn to create a Java Program to check Input Numbers is vowel or consonant in Java using Java programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following Java programming topics:
- Java Operators.
- Basic Input and Output function in Java.
- Class and Object in Java.
- Basic Java programming.
- If-else statements in Java.
- For loop in Java.
Vowel
A vowel is a letter that speak with an open sound without closing any part of the mouth is called as vowel.
Example : a,e,i,o,u.
Consonant
A consonant is a speech sound that is not a vowel.
Example:- As we know a,e,i,o,,u are called vowels. And renaming are called consonants.
Java Program to check whether input character is vowel or consonant
In this program we will learn to create a Program that checks weather input character is Vowels and Consonants .We would first declared and initialized the required variables. Next, we would prompt user to input a character. Later in program we will find inputted character is Vowels or Consonants .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
// Java program t fin given character is vowel or Consonant import java.util.Scanner; class Cont_vow_cons { public static void main(String[] args) { // Declaring and taking value form user... Scanner sc = new Scanner(System.in); System.out.println("please enter any charcater"); char ch = sc.next().charAt(0); // checking character is any of a, e, i, o, u .. if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { System.out.println("Vowels: " + ch); } // check if character is not in between a to z else if ((ch >= 'a' && ch <= 'z')) { System.out.println("Consonants: " + ch); } } } |
Output
Vowel
Consonant
In the above program, we have first declared and initialized a set variables required in the program.
- ch= it will hold given character.
And in the next statement we will ask user to input Character as shown in picture below.
After taking value from user with the help of “if-else” statement we will check the inputted character is a vowel or consonant, using following logic.
Logic For Vowel.
For Consonant.
Note : Inputted value by user must be a Character.