Write a program that Asks the user to enter a word If word s

Write a program that: Asks the user to enter a word. If word starts with a vowel, the program prints that it starts with a vowel. If word starts with a consonant, the program prints that it starts with a consonant. If word starts with neither a vowel nor a consonant (e.g., it starts with a number, or a punctuation character, or it is the empty string), the program prints that it starts with neither a vowel nor a consonant. Example Program Run: Please enter a word: 543 543 starts with neither a vowel nor a consonant. Example Program Run: Please enter a word: Airplane Airplane starts with a vowel. Example Program Run: Please enter a word: cat cat starts with a consonant.

Solution

import java.util.Scanner;

public class WordStart{

public static void main(String []args) {
Scanner scanner = new Scanner(System.in);
String inputWord, message;
System.out.print(\"Please enter a word: \");

inputWord = scanner.nextLine();
message = inputWord + \" \";
  
if(inputWord.toLowerCase().charAt(0) >= \'a\'
           && inputWord.toLowerCase().charAt(0) <= \'z\'){
switch(inputWord.toLowerCase().charAt(0)){
case \'a\':
case \'e\':
case \'i\':
case \'o\':
case \'u\':
message += \"starts with a vowel.\";
break;
default:
message += \"starts with a consonant.\";
}
}
else {
message += \"starts with neither a vowel nor a consonant.\";
}
      
System.out.print(message);
}
}

 Write a program that: Asks the user to enter a word. If word starts with a vowel, the program prints that it starts with a vowel. If word starts with a consona

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site