English, asked by lasnapurevaishnavi, 1 month ago

write a program to enter any alphabet :p it is not an vowel writing in java if else if and switch statement​

Answers

Answered by ItzMeSam35
3

import java.util.*Scanner;

public class VowelOrConstonant

{

public static void main (String args[])

{

Scanner sc=new Scanner (System.in);

System.out.print("Enter A Character : ");

char myChar = sc.next().charAt(0);

if ( ( myChar >= 'a' && myChar <= 'z' ) || ( myChar >= 'A' && myChar <= 'Z' ))

CheckVowelOrConsonant(myChar);

else

System.out.println(myChar + " is not an alphabet");

sc.close();

}

static void CheckVowelOrConsonant (char ch)

{

if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||

ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')

System.out.println("Character " +ch+ " is a Vowel");

else

System.out.println("Character "+ch+ " is a Consonant");

}

}

Similar questions