小程序-----统计字符串中数字,中文,空格,字母的个数

来源:互联网 发布:淘宝自己开店套现 编辑:程序博客网 时间:2024/06/06 09:19
public class Test2 {
public static void main(String[] args) {
   int daNum=0;//数字个数
   int chineseNum=0;//中文个数
   int englishNum=0;//英文个数
   int nullNum=0;//空格个数


   String name="kwq h22dj qw3h很好";

for(int i =0;i<name.length();i++){

char ch = name.charAt(i);

if(ch>'0'&&ch<'9'){
daNum++;
}else  if((ch>'a'&& ch<'z')||(ch>'A'&& ch<'Z')){
englishNum++;
}else if(ch==' '){
nullNum++;
}else{
chineseNum++;
}

}
}
}
0 0
原创粉丝点击