7-26 单词长度

7-26 单词长度_第1张图片

import java.util.Scanner;

class test26 {
     public static void main(String[] args) {
    
     Scanner input=new Scanner(System.in);
        String s=""; s = input.nextLine();
        input.close();
        String[] split = s.trim().split("\\s+");
        for (int i=0;i<split.length;i++) {
            if (split[split.length-1].length()>1) {//最后一个是[XXX.]
                if (i==split.length-1) {
                    System.out.print(split[i].length()-1);
                }else{
                    System.out.print(split[i].length()+" ");
                }
            }else{//最后一个是[.]
                if (i<split.length-2) {
                    System.out.print(split[i].length()+" ");
                }else if(i==split.length-2){
                    System.out.print(split[i].length());
                }else{
                   ;
                }
            }

        }

    }}

你可能感兴趣的:(PAT,pat)