Free CoreJava Programs Source codes | Examples | Video Tutorials Download

Wednesday, January 21, 2009

Vowel Or Consonant Check

import java.io.BufferedReader;

import java.io.InputStreamReader;

/**

* To check whether an input (single character) is a vowel or a consonant,

* and print accordingly

*/

public class VowelConsonant

{

/**

* check whether the given input character is vowel or not

* display appropriate message

* @throws Exception

*/

public static void checkVowel() throws Exception

{

BufferedReader brConsole=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter any alphabet : ");

String strInput=brConsole.readLine();

if(strInput.length()!=1)

System.out.println(strInput + " Is Invalid Input!!!");

else

{

int intNo=(char)strInput.charAt(0);

if((intNo>=65 && intNo<=90) || (intNo>=97 && intNo<=122))

{

char chChar=(char)intNo;

switch(chChar)

{

case 'a':

case 'e':

case 'i':

case 'o':

case 'u':

case 'A':

case 'E':

case 'I':

case 'O':

case 'U':

System.out.println(chChar + " is vowel");

break;

default:

System.out.println(chChar + " is consonent");

}

}

else

{

System.out.println("Error : Invalid Input!!!");

return;

}

}

}

/**

* excecution begin from here

* @param args

*/

public static void main(String[] args)

{

try

{

checkVowel();

}

catch(Exception e)

{

System.out.println("Error occured!!");

}

}

}

No comments:

Post a Comment

Followers