黑马程序员技术交流社区

标题: 请统计和打印出字符串中包含中文字符、英文字符和数字字符的个数。 [打印本页]

作者: 段燚涛    时间: 2015-8-5 10:15
标题: 请统计和打印出字符串中包含中文字符、英文字符和数字字符的个数。
有一个字符串,其中包含中文字符、英文字符和数字字符,请统计和打印出
各个字符的个数。

作者: 段燚涛    时间: 2015-8-5 10:18
  1. int engishCount;
  2. int chineseCount;
  3. int digitCount;
  4. for(int i=0;i<str.length;i++)
  5. {
  6. charch = str.charAt(i);
  7. if(ch>=’0’&& ch<=’9’)
  8. {
  9. digitCount++
  10. }
  11. elseif((ch>=’a’&& ch<=’z’) || (ch>=’A’ && ch<=’Z’))
  12. {
  13. engishCount++;
  14. }
  15. else
  16. {
  17. chineseCount++;
  18. }
  19. }
  20. System.out.println(……………);
复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2