package org.zhy.demo.algorithm;
/**
* 有一个字符串,其中包含中文字符、英文字符和数字字符,请统计和打印出各个字符的个数
*
* @author Administrator
*
*/
public class Str {
public static void main(String[] args) {
String str = "adasfAAADFD阿萨德发123";
int unicodeCount = 0;
int szCount = 0;
int zmCount = 0;
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c >= '0' && c <= '9') {
szCount++;
}else if((c >= 'a' && c<='z') || (c >= 'A' && c<='Z')){
zmCount++;
}else{
unicodeCount++;
}
}
System.out.println(unicodeCount);
System.out.println(szCount);
System.out.println(zmCount);
}
}