题解 | #统计字符#

统计字符

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String str = in.nextLine().toLowerCase();
            int[] res = {0,0,0,0};
            for(char b:str.toCharArray()){
                if(b>='a'&&b<='z') res[0]++;
                else if(b==' ') res[1]++;
                else if(b>='0'&&b<='9')res[2]++;
                else res[3]++;
            }
            for(int b:res){
                System.out.println(b);
            }
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
人力小鱼姐:实习经历没有什么含金量,咖啡店员迎宾这种就别写了,其他两段包装一下 想找人力相关的话,总结一下个人优势,结合校园经历里有相关性的部分,加一段自我评价
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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