Word length --mooc "zero-based learning Java language" - (Zhejiang Weng Kai) sixth week of programming that (1)

Title Contents:

Your program should read a line of text, separated by a space in which a number of words, to '' end. This line of text you want to output the length of each word. Here word and language-independent, may include various symbols, such as "it's" count a word length of 4. Note consecutive spaces may appear line.

 

Input formats:

In the given input row line of text, with '.' End, the end of the period length can not be calculated in the last word.

 

Output formats:

This corresponds to the output line of text in a word line length, the length of a space between each of the spaced apart, no final end of the line spaces.

 

Sample input:

It's great to see you here.

 

Sample output:

4 5 2 3 3 4

Time limit: 500ms Memory Limit: 32000kb
 
Code:
/ * 
Word length (5 minutes) 
Title Contents: 
Your program to read a line of text, separated by a space in which a number of words to end '.'. This line of text you want to output the length of each word. Here word and language-independent, may include various symbols, such as "it's" count a word length of 4. Note consecutive spaces may appear line. 

Input format: 
input line is given a line of text, to end, the end of the period length can not be calculated within the last word '.'. 

Output format: 
output line lengths of the line of text words corresponding to each length separated by a space, not the final end of the line spaces. 

Sample input: 
It apos to Great See you here Wallpaper. 

Output Sample: 
452 334 
Time limit: 500ms memory limit: 32000kb 
 * / 
Import java.util.Scanner; 

public  class word length { 

    public  static  void main (String [ ] args) {
         // the TODO Auto-Generated Method Stub; 
        Scanner in = new new Scanner (the System.in); 
        String S;
        S = in.nextLine (); // input string 
        String [] = arrayString s.split ( "\\ S +"); // if there is a string or more spaces divided in this standard 
        for ( int I = 0; I <arrayString.length; I ++ ) 
        { 
            iF !! (arrayString [I] .length () = 0 && arrayString [I] .endsWith ( ".")) // string length is not zero, and when when not at the end.
                                                                          // precondition is to prevent the strings have many spaces in front of the case 
            { 
                System.out.println (arrayString [I] .length () + "" ); 
            } 
            the else  IF ((arrayString [I] .length () - 1)! = 0 && arrayString [ i] .endsWith ( "."When the string ends., And the string length is not decremented to zero.
                                                                                 // when the preconditions as noted there may be many string space behind 
            { 
                System.out.println (arrayString [I] .length () -1 ); 
            } 
        } 

    } 

}

 

Guess you like

Origin www.cnblogs.com/daimasanjiaomao/p/10939239.html