练习三:统计字符串中字符中 大写字符 小写字符 数字 其他字符 出现的次数

时间:2023-02-13 21:54:32
package com.heima.test;

public class StringTest {

/**练习三:统计字符串中字符中 大写字符 小写字符 数字 其他字符 出现的次数
*
* @param args
*/

public static void main(String[] args) {
String s = "AHDKUEjsh1243dke234idj@#346$%^&456*()!";
int small = 0;
int big = 0;
int num = 0;
int other = 0;
for(int i= 0; i< s.length();i++){
char c = s.charAt(i);
if(c >= 'a' && c <= 'z'){
small++;
}else if(c >= 'A' && c <= 'Z'){
big++;
}else if(c >= '0' && c <= '9'){
num++;
}else{
other++;
}
}
System.out.println("大写字母有:"+big+"小写字母有:"+small+"数字有: "+num+"其他字符有:"+other);
}

}