Cycle-06. Count the number of words in a line of text (15)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.