Source of the topic:
Cycle-06. Count the number of words in a line of text (15) time limit MS
Memory Limit 65536 KB
Code length limit 8000 B
Procedures for the award of questions StandardAuthor Zhang Tong Hongyu (Zhejiang University)
This topic requires a program to count the number of words in a line of characters. The so-called "word" refers to a continuous string without spaces, separated by a space between the words, the number of spaces can be multiple.
Input format:
The input gives a line of characters.
Output format:
Outputs the number of words in a row.
Input Sample:
Let's go to the 209.
Sample output:
5
Code:
Import Java.io.ioexception;import java.text.decimalformat;import Java.text.parseexception;import Java.util.Scanner ;p Ublic class Main {public static void Main (string[] args) throws ParseException, IOException { Scanner Scanner = New Scanner (system.in); String str = scanner.nextline (). Trim (); Very important, if the console input is all spaces, need special handling if (Str.equals (")) System.out.println (0); else { string[] STRs = str.split ("+"); System.out.println (Strs.length);}}}
Cycle-06. Count the number of words in a line of text (15)