给定一个字符串str,求里面大写字母,小写字母,以及其他字符的个数?

public static void main(String[] args) {
		String str="fhudsfvdUJIKLIUvd3253252";
		int m = 0;
		int n = 0;
		int k = 0;
		char[] a = str.toCharArray();
		for (char ch : a){
			if(ch >= 'a' && ch <= 'z'){
				m = m + 1;
			}else if (ch >= 'A' && ch <= 'Z'){
				n = n + 1;
			}else k = k + 1;
		}
		System.out.println("小写字符个数:"+m);
		System.out.println("大写字符个数:"+n);
		System.out.println("其他字符个数:"+k);
	}

 

你可能感兴趣的:(面试题)