P5015标题统计

题意:

 凯凯刚写了一篇美妙的作文,请问这篇作文的标题中有多少个字符? 注意:标题中可能包含大、

小写英文字母、数字字符、空格和换行符。统计标题字 符数时,空格和换行符不计算在内。

 

 

import java.util.*;
public class Main {
    public static void main(String[] args) {
        // TODO 自动生成的方法存根   
        Scanner in=new Scanner(System.in);
        String s=in.nextLine();
        String [] str=s.split(" ");//分割数组,用空格进行分割
        int count=0;
        for(int i=0;i<str.length;i++)
        {
            count+=str[i].length();
        }
        System.out.println(count);
    }
}

 

猜你喜欢

转载自www.cnblogs.com/coke-/p/12708539.html