JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class WordDisplay{
public static void main(String[] b){
int a=1;
for (String s : new java.util.Scanner(System.in).nextLine().split(" ")) System.out.print(s.equals("")? "" : ("word "+ a++ +":"+s+"\n")); }}
/* CHALLENGE: Counting And Display Strings
Write a program that captures a string that can contain spaces and displays each word in the string, the separator being the space.
Example, for the input: "I think so I am"
The program displays:
word 1: I
word 2: think
word 3: so
word 4: I
word 5: am
And finally it shows how many words the sentence has.
Good luck.
*/
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run