Advertisement

Write a Program in Java to Check if a Character is an Uppercase Vowel or Lowercase Vowel or Not

 

Write a program in Java to check if a character is an uppercase vowel or lowercase vowel or not

Write a Program in Java to Check if a Character is an Uppercase Vowel or Lowercase Vowel or Not

In this program, we are going to check whether a user-inputted alphabet is in an uppercase vowel or in a lowercase vowel or not. The file name is MyVowelCheck.java so the main class name is MyVowelCheck. Here I'm using the Scanner class to receive user-inputted character values. 

To check whether the input is a proper alphabet or some special character, or to check whether it is in uppercase or in lowercase, we have to determine the ASCII value of that given character. By the use of ASCII values, we can say our desired result. 

To get the ASCII value of the character, we have to typecase the variable in integer format. The int value of a char variable returns the ASCII value associated with it.

Now there is a range in ASCII values to obtain inputted character is an alphabet or not. The ASCII range for the lowercase alphabets is between 65 to 90 and the ASCII range for the uppercase alphabets is between 97 to 122. After checking the range we have to check for the ASCII values of a,e,i,o,u vowels from the English alphabet sets. As per the corresponding ASCII value, we have to print whether the inputted alphabet is an uppercase vowel or a lowercase vowel or not. 

Filename:- MyVowelCheck.java

import java.util.Scanner;
public class MyVowelCheck{
public static void main(String args[])
{
char v; //variable to store the character
System.out.println("Enter the character:"); //prompting user to enter the character value
Scanner s=new Scanner(System.in);
v=s.next().charAt(0); //the user-inputted cahracter is stored in the variable
//System.out.println("ASCII ="+(int)v); [printing the ASCII value of the inputted character]
if(((int)v>=65)&&((int)v<=122)) //legal range
{
if(((int)v>=91)&&((int)v<=96)) //range for some special characters
{
System.out.println("Not an alphabet");
}
else //range for the English alphabet
{
switch((int)v)
{
case 65: //ascii for A
case 69: //ascii for E
case 73:
case 79:
case 85: System.out.println("Uppercase Vowel");break;
case 97: //ascii for a
case 101: //ascii for e
case 105: //ascii for i
case 111:
case 117: System.out.println("Lowercase Vowel");break;
default: System.out.println("Not a Vowel");
}
}
}
else //illegal range for an alphabet
System.out.println("Not an alphabet");
}
}

Output:-

output of java vowel case check


Post a Comment

0 Comments