编写一个程序,输出一个字符串中的大写英文字母数,小写英文字母数以及非英文字母数。


 1 public class Test {
 2     public static void main(String args[]) {
 3         String s = "aaABDFcddreji$^#^&^%12575hhdshhiJKJLIU";
 4         int lowerCaseCount = 0;
 5         int upperCaseCount = 0;
 6         int unCaseCount = 0;
 7         for(int i = 0; i < s.length(); i++) {
 8             char c = s.charAt(i);
 9             if(c >= 'a' && c <= 'z') {
10                 lowerCaseCount++;
11             }else if(c >= 'A' && c <= 'Z') {
12                 upperCaseCount++;
13             }else {
14                 unCaseCount++;
15             }
16         }
17         System.out.println("小写字母个数为: " + lowerCaseCount);
18         System.out.println("大写字母个数为: " + upperCaseCount);
19         System.out.println("非字母个数为: " + unCaseCount);
20     }
21 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM