文字小文字大文字を求める文字列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);
	}

 

公開された48元の記事 ウォンの賞賛1 ビュー2839

おすすめ

転載: blog.csdn.net/Forest24/article/details/90211182