求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() + "个"); }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 Vue3 大型图片数据拖动排序
- ¥15 划分vlan后不通了
- ¥15 GDI处理通道视频时总是带有白色锯齿
- ¥20 用雷电模拟器安装百达屋apk一直闪退
- ¥15 算能科技20240506咨询(拒绝大模型回答)
- ¥15 自适应 AR 模型 参数估计Matlab程序
- ¥100 角动量包络面如何用MATLAB绘制
- ¥15 merge函数占用内存过大
- ¥15 使用EMD去噪处理RML2016数据集时候的原理
- ¥15 神经网络预测均方误差很小 但是图像上看着差别太大