Given a String sentence entered by the user. Print each word on a separate line with the word #. For example, If the sentence "The cat in the hat" was entered, the following would be the output
word #1: The
word #2: cat
word #3: in
word #4: the
word #5: hat
Scanner input = new Scanner (System.in);
String sentence;
String words = "";
int count = 1;
sentence = input.nextLine();
for (int i = 1; i < sentence.length(); i++)
{
if (sentence.charAt(i) == ' ')
count++;
}
{
words = sentence.substring(0,sentence.indexOf(' '));
System.out.println(words);
}
.split().int i = 0;.