Prompt the user to enter a sentence. Output that sentence with spacing corrected
ID: 3638544 • Letter: P
Question
Prompt the user to enter a sentence. Output that sentence with spacing corrected and with letters corrected for capitalization. In other words, in the output sentence, all strings of two or more blanks should be compressed to a single blank. The sentence should start with an upper case letter but should contain no other uppercase letters. Do not worry about proper names. Treat a line break as if it were a blank, in that a line break and any number of blanks are compressed to a single blank.. Assume the sentence ends with a period and contain no other periods. For example, the input:
the Answer to life, the Universe, and everything
IS 42
should produce the following output:
The answer to life, the universe, and everything is 42.
Explanation / Answer
I will not write the Java code for you, but I can refer you to some useful methods/links: One way of getting inputs: System.in.read: http://www.java2s.com/Code/JavaAPI/java.lang/Systeminread.htm One way of checking characters: "some string".charAt(n), where n is the position of the character. charAt(0) in this case would return 's'. One way of removing characters: "some string".substring(start, end) - this is a little more tricky, so below are some examples of how to use it: "some string".substring(0, 1) -> returns "s" "some string".substring(2, 4) -> returns "me" One way to make a letter capitalized/lower case: Character.toUpperCase(char c); Character.toLowerCase(char c); I believe this is all the methods you really need. Just remember that ' ' is usually a new line. More over, remember that you can combine strings and characters ("my strin" + 'g' is valid). Good luck.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.