import java.util.concurrent.TimeUnit; import java.util.Date; import java.util.Random; import java.util.*; public class wz { public static void main(String[] args) throws Exception{ int engishCount=0; int chineseCount=0; int digitCount=0; //String str ="中国aadf的111萨bbb菲的zz 萨 菲"; //String str ="中国aadf的11"; String str ="中国aadf的111萨bb陕西重庆"; for(int i=0;i<str.length();i++) { char ch = str.charAt(i); if(ch>=‘0‘&& ch<=‘9‘) digitCount++; else if((ch>=‘a‘&& ch<=‘z‘) || (ch>=‘A‘&& ch<=‘Z‘)) { engishCount++; } else chineseCount++; } System.out.println("chineseCount = "+chineseCount); System.out.println(" engishCount= "+engishCount); System.out.println("digitCount = "+digitCount); } }
测试结果为 空格计入汉字………………
时间: 2024-10-14 19:45:06