题解 | #统计字符#

统计字符

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

import java.util.Scanner;

public class Main { public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);
    String str = scanner.nextLine();        
    //英文
    String aStr = str.replaceAll("([A-Za-z])", "");
    int aCount = str.length() - aStr.length();
    System.out.println(aCount);

    //空格
    String kongStr = str.replaceAll(" ", "");
    int kongCount = str.length() - kongStr.length();
    System.out.println(kongCount);

    //数字
    String numStr = str.replaceAll("([0-9])", "");
    int numCount = str.length() - numStr.length();
    System.out.println(numCount);

    //其他
    System.out.println(str.length() - aCount - kongCount - numCount);
}

}

全部评论

相关推荐

CARLJOSEPH...:宝宝你戾气太大了
点赞 评论 收藏
分享
机械打工仔:有说的你怀疑一下就行了,直接问也太实诚了
点赞 评论 收藏
分享
05-23 19:02
吉林大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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