求java大佬
假设某文件中的字符包含有大小写英文字母阿拉伯数字等,请编程分别统计写字母、小写字母、阿拉伯数字及其它字符的个数飞入数组并输出.
2条回答 默认 最新
limit、T 2021-06-07 11:22关注public static void main(String[] args) { String str = "AFkf679afKAJKsf9uj=-`1lksSFf/.,p';l"; String wordAndNumber = str.replaceAll("\\W", ""); String word = wordAndNumber.replaceAll("\\d", ""); Integer upCount = word.replaceAll("[a-z]", "").length(); Integer lowCount = word.replaceAll("[A-Z]", "").length(); String number = wordAndNumber.replaceAll("[a-zA-Z]", ""); String other = str.replaceAll("\\w", ""); System.out.println("大写字母为:" + upCount + "个"); System.out.println("小写字母为:" + lowCount + "个"); System.out.println("阿拉伯数字个数为:" + number.length() + "个"); System.out.println("其他字符个数为:" + other.length() + "个"); }本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报