String unitCode = "中国"; char[] charArray = unitCode.toCharArray(); int cnorEn = 0; for (char c : charArray) { cnorEn =+ isCnorEn(c); } if(cnorEn < 100){ System.out.println("中文字符" + unitCode); }else{
System.out.println("英文字符" + unitCode); }
static int isCnorEn(char c){ if(c >= 0x0391 && c <= 0xFFE5) { //中文字符 return 1; } if(c>=0x0000 && c<=0x00FF){ //英文字符 return 101; } return 0; }