有一个字符串,其中包含中文字符、英文字符和数字字符,请统计和打印出各个字符的个数。


如果一串字符如"aaaabbc中国1512"要分别统计英文字符的数量,中文字符的数量,和数字字符的数量,

假设字符中没有中文字符、英文字符、数字字符之外的其他特殊字符。

View Code
 1 package com.aspire.test;
 2 
 3 public class Test {
 4     public static void main(String[] args) {
 5         
 6         String str = "aaaabbc中国1512";
 7         int engishCount = 0;
 8         int chineseCount = 0;
 9         int digitCount = 0;
10         for(int i=0;i<str.length();i++)
11         {
12             char ch = str.charAt(i);
13             if(ch>='0' && ch<='9')
14             {
15                 digitCount++;
16             }
17             else if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
18             {
19                 engishCount++;
20             }
21             else
22             {
23                 chineseCount++;
24             }
25         }
26         System.out.println("....");
27 
28     }
29 }

 


免责声明!

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



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