题解 | #统计字符#

统计字符

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

import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()) {
            String input = scan.nextLine();
            String str1 = input.replaceAll("[^a-zA-Z]","");
            String str2 = input.replaceAll("[^ ]","");
            String str3 = input.replaceAll("[^0-9]","");
            String str4 = input.replaceAll("[a-zA-Z0-9 ]","");
            System.out.println(str1.length());
            System.out.println(str2.length());
            System.out.println(str3.length());
            System.out.println(str4.length());
        }
    }
}
全部评论

相关推荐

object3:开始给部分🌸孝子上人生第一课了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务