Question: Write a java program that gets a one-line sentence from the user, and then outputs one of several responses, as follows: If the sentence ends
Write a java program that gets a one-line sentence from the user, and then outputs one of several responses, as follows:
If the sentence ends with a question mark '?' and the sentence contains an even number of characters, output to the screen the words: That's an even question.
If the sentence ends with a question mark '?' and the sentence contains an odd number of characters, output to the screen the words: That's an odd question.
If the sentence ends with an exclamation mark '!', output to the screen the word: Wow!
For all other cases, output the words: You always say, " followed by the sentence entered by the user. In your output, display double quotes around the user's sentence.
When testing your program, make sure that you are checking for the correct conditions. For example, make sure your program still works correctly if there is a question mark in the middle of the sentence, rather than at the end.
The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on what values that the user types in while the program runs. The user's inputted values are shown below in italics:
Enter a sentence or question: How now brown cow? That's an even question.
Here is another example run of the program:
Enter a sentence or question: What is art? Is art, art? That's an odd question.
Here is another example run of the program:
Enter a sentence or question: What now? Oh, I see! Wow!
Here is another example run of the program:
Enter a sentence or question: The meaning of life is... You always say, "The meaning of life is..."
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
