JAVA | Check by ASCII weather a single input character is vowel or consonant?

PRACTICE AND LEARN 

JAVA

         

         

 (ASCII, Input a character)


Q. Check an alphabet, Weather it is vowel or consonant? (Using ASCII number, taking an input character)

 

 

Tips: 

 

 ** Build your algorithm** 

 

 

 

 

Hints for building:

1) Take input character from user.

2) Convert into ASCII number.

3) Check vowel or consonant ASCII number.

4) Use if and else.

5) print the character from user.



Packages Required:

The package required is java.util. we have to import it by snippet code. Scanner class is used from java.util package to get user input.
import java.util.Scanner;
 

How to take input a character ? :

 
We have used the next().charAt();  method, for read a character.
Scanner read = new Scanner(System.in);
char a = read.next().charAt(0);
 
 
 

**Try once before seeing the code**

 

 

 JAVA Code :

import java.util.Scanner;
public class ASCII_Alphabet{
public static void main(String[] args){
Scanner read = new Scanner(System.in);
char a = read.next().charAt(0);
int b = a;
if(b == 97 || b == 101 || b == 105 || b == 111 || b == 117){
System.out.println( a + " is Vowel");
}
else{
System.out.println(a + " is consonant");
}
}
}
 

Output :

 

 

 
-------------------------------**------------------- 

Comments

Post a Comment

Give your feedback!
DO NOT SPAM !!
NO THIRD PARTY PROMOTIONAL LINK !!!! (else comment will be deleted.)

Popular posts from this blog

Print name in a pattern | name as abbreviation | C-Program