题解 | #统计字符#

统计字符

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

import java.util.Scanner;

public class Main{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); String next = scan.nextLine(); String trim = next.replace(" ",""); char[] chars = trim.toCharArray(); int x=0; int y=0; int z=0; for (int i = 0; i < chars.length; i++) { if (chars[i]>='a'&chars[i]<='z'){ x++; } if (chars[i]>='A'&chars[i]<='Z'){ x++; } if (chars[i]>='0'&chars[i]<='9'){ y++; }

    }
    z=chars.length-x-y;
        int num=next.length()-chars.length;
        System.out.println(x);
        System.out.println(num);
        System.out.println(y);
        System.out.println(z);
}

}

全部评论

相关推荐

04-03 15:12
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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