题解 | #统计字符#

统计字符

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);
    }
}

全部评论

相关推荐

09-17 17:33
门头沟学院 Java
阿里面试一直在聊天是不是就是kpi了
offer收割机jo...:应该不是KPI,因为好多人阿里简历都过不去
我的秋招日记
点赞 评论 收藏
分享
09-16 14:01
井冈山大学 Java
肖先生~:兄弟们,我发的她都点赞了,但是就是不给我微信
秋招被确诊为……
点赞 评论 收藏
分享
迷茫的大四🐶:当你得到一些东西,那这些东西就会变成基本项,你有别人也有
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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