题解 | #统计字符#

统计字符

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



public class test{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        if(sc.hasNext()){
            String str = sc.nextLine();
            //对所有字符进行替换,使之不存在
            String word = str.replaceAll("[a-zA-Z]", "");
            //得到所有字符的个数
            System.out.println(str.length()-word.length());
            //对所有数字进行替换,使之不存在
            String num = str.replaceAll("[0-9]", "");
            System.out.println(str.length()-num.length());
            //对所有空格进行替换,使之不存在
            String blank = str.replaceAll(" ", "");
            System.out.println(str.length()-blank.length());
            //其他的,通过总长度来进行减法
            System.out.println(word.length()+num.length()-2*str.length()+blank.length());
        }
    }
全部评论

相关推荐

这是什么操作什么意思,这公司我服了...
斯派克spark:意思是有比你更便宜的牛马了
点赞 评论 收藏
分享
06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
怎么起名字:早知道就不读书了,害得我送外卖还得扶眼镜
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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