Given a string str, which seek capital letters lowercase letters, as well as the number of other characters?

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);
	}

 

Published 48 original articles · won praise 1 · views 2839

Guess you like

Origin blog.csdn.net/Forest24/article/details/90211182
Recommended