《JAVA统计一个String对象中大写字母小写字母非字母各自出现的个数》由会员分享,可在线阅读,更多相关《JAVA统计一个String对象中大写字母小写字母非字母各自出现的个数(2页珍藏版)》请在金锄头文库上搜索。
/*统计一个 String 对象中大写字母 小写字母 非字母 各自出现的个数*/class TestString_3public static void main(String args)String str = abAM1,!23;int cntU = 0; /大写字母的个数int cntL = 0; /小写字母的个数int cntOther = 0;int i;/第二种方法String s1 = ABCDEFGHIJKLMNOPQRSTUVWXYZ;String s2 = abcdefghijklmnopqrstuvwxyz;for (i=0; i=a & ch=A & ch=Z)/ cntU+;/ / else / cntOther+;/ / System.out.printf(大写字母个数: %dn, cntU);System.out.printf(小写字母个数: %dn, cntL);System.out.printf(非字母个数: %dn, cntOther);