题解 | #统计字符#

统计字符

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int[] arr = new int[4];
        for (char c : line.toCharArray()) {
            String s = String.valueOf(c);
            if (s.matches("[a-zA-Z]")) {
                arr[0] += 1;
            } else if (s.equals(" ")) {
                arr[1] += 1;
            } else if (c >= '0' && c <= '9') {
                arr[2] += 1;
            } else {
                arr[3] += 1;
            }
        }
        for (int i : arr) {
            System.out.println(i);
        }
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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