Q:

(Vowel or consonant?) Write a program that prompts the user to enter a letter and check whether the letter is a vowel or consonant. Here is a sample run:

0

(Vowel or consonant?) Write a program that prompts the user to enter a letter and check whether the letter is a vowel or consonant. Here is a sample run:

Output:

Enter a letter: B
B is a consonant


Enter a letter grade: a
a is a vowel


Enter a letter grade: #
# is an invalid input

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

/*
(Vowel or consonant?) Write a program that prompts the user to enter a letter and
check whether the letter is a vowel or consonant.
*/
import java.util.Scanner;

public class Exercise_04_13 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		// Prompt the user to enter a letter
		System.out.print("Enter a letter: ");
		String s = input.nextLine();
		char ch = s.charAt(0);

		if (Character.isLetter(ch))
		{
			switch(Character.toUpperCase(ch))
			{
				case 'A': 
				case 'E': 
				case 'I': 
				case '0': 
				case 'U': System.out.println(ch + " is a vowel"); break;
				default : System.out.println(ch + " is a consonant"); 
			}
		}
		else
			System.out.println(ch + " is an invalid input");
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now