题解 | #统计字符#

统计字符

https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5

import java.util.*;
import java.lang.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] strs = in.nextLine().split("");
        int letters=0,nums=0,spaces=0,others=0;
        for(String str: strs){
            if(str.matches("[a-zA-Z]")){
                letters++;
            }else if(str.matches("[0-9]")){
                nums++;
            }else if(str.equals(" ")){
                spaces++;
            }else{
                others++;
            }
        }

        System.out.println(letters);
        System.out.println(spaces);
        System.out.println(nums);
        System.out.println(others);
    }
}

全部评论

相关推荐

爱吃肉的伊登在写日记:好棒,27届简历能做成这个样子,但是第一个项目感觉cover住难度还是不小的,特别是二面的时候肯定要对分布式系统设计这一块儿有高出正常面试者的水平才行
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务