题解 | #统计字符#

统计字符

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 letter = 0;
        int space = 0;
        int digit = 0;
        int other = 0;
        for (char c : line.toCharArray()) {
            if (Character.isLetter(c)) {
                letter++;
            } else if (Character.isSpaceChar(c)) {
                space++;
            } else if (Character.isDigit(c)) {
                digit++;
            } else {
                other++;
            }
        }
        System.out.println(letter);
        System.out.println(space);
        System.out.println(digit);
        System.out.println(other);
    }
}
全部评论

相关推荐

06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
评论
1
5
分享

创作者周榜

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