Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program that prompts the user to provide single character from the alpha

ID: 3629447 • Letter: W

Question

write a program that prompts the user to provide single character from the alphabet. Print vowel or consonant depending on the user input. The program prints error if the user input is not a letter (between a and z or A and Z), or the user input is a string of length>1

Explanation / Answer

Scanner keyboard=new Scanner(System.in); String in; System.out.println("Enter a letter from the alphabet"); in=keyboard.nextLine(); if (in.length()>1) { System.out.println("Error"); System.exit(0); } char letter=in.charAt(0); if (letter=='a'||letter=='e'||letter=='i'||letter=='o'||letter=='u' ||letter=='A'||letter=='E'||letter=='I'||letter=='O'||letter=='U') { System.out.println("vowel"); } else { System.out.println("consonant"); }