編寫一個程序,輸出一個字符串中的大寫英文字母數,小寫英文字母數以及非英文字母數。


 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