String s = new Scanner(System.in).nextLine(); //利用正则表达式,替换replaceAll(删除)别的。剩下的就是要求的长度 System.out.println(s.replaceAll("[^a-zA-Z]","").length()); System.out.println(s.replaceAll("\\S","").length()); System.out.println(s.replaceAll("\\D","").length()); System.out.println(s.replaceAll("[\\s\\da-zA-Z]","").length());
1

相关推荐

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