Question
Using Java: Write a program that asks the user to enter a sentence. Using matches method using only one pattern validate that the entered sentence
Using Java: Write a program that asks the user to enter a sentence. Using matches method using only one pattern validate that the entered sentence consists only of letters and ends with either: a period, an exclamation mark, or a question mark. To check if the given string represents a valid sentence define a pattern. If it is not a valid sentence, your program should output that the input is not valid. Otherwise the input should be displayed with all the vowels replaced with an #character
The following shows sample runs of the program:
Run #1
Please enter a sentence that consists of letters only and ends with a period, an exclamation mark, or a question mark
The first sentence is not valid
The entered input "The first sentence is not valid" is not a valid.
Run #2
Please enter a sentence that consists of letters only and ends with a period, an exclamation mark, or a question mark
The 2nd sentence is also invalid!
The entered input "The 2nd sentence is also invalid!" is not a valid.
Run #3
Please enter a sentence that consists of letters only and ends with a period, an exclamation mark, or a question mark
A very NICE sentence.
The entered input: "A very NICE sentence."
with all vowels replaced is: "# v#ry N#C# s#nt#nc#."
Run #4
Please enter a sentence that consists of letters only and ends with a period, an exclamation mark, or a question mark
Do you like programming?
The entered input: "Do you like programming?"
with all vowels replaced is: "D# y## l#k# pr#gr#mm#ng?"
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started