还是正则表达式帅,我这个写的非常丑陋 public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { String str = in.nextLine(); str = str.toLowerCase(); String engCh = "abcdefghijklmnopqrstuvwxyz"; String figCh = "0123456789"; String space = " "; int countEng = 0; int countFig = 0; int countSpace = 0; int elseCh = 0; for (int i = 0; i < str.length(); i++) { if (engCh.contains(Character.toString(str.charAt(i)))) { countEng++; } else if (figCh.contains(Character.toString(str.charAt(i)))) { countFig++; } else if (space.contains(Character.toString(str.charAt(i)))) { countSpace++; } else { elseCh++; } } System.out.println(countEng); System.out.println(countSpace); System.out.println(countFig); System.out.println(elseCh); } }
点赞

相关推荐

不愿透露姓名的神秘牛友
11-26 15:46
已编辑
字节国际 电商后端 24k-35k
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客网
牛客企业服务