统计字符串中,中文字符、英文字符和数字字符的数量

package com.suanfa;

public class ZYSTotal {
	/**
	 * 统计字符串中,中文字符、英文字符和数字字符的数量
	 */
	public static void main(String[] args) {
		int englishCount=0;
		int chineseCount=0;
		int digitCount=0;
		
		String str="你好啊nihaoa9999999";
		for(int i=0;i<str.length();i++){
			char ch=str.charAt(i);
			if(ch>='0'&&ch<='9'){ //数字
				digitCount++;
			}else if((ch>='a'&&ch<'z')||(ch>='A'&&ch<'Z')){
				englishCount++;
			}
			else{
				chineseCount++;
			}
		}
		
		System.out.println("中文字符的数量: "+chineseCount);
		System.out.println("英文字符的数量: "+englishCount);
		System.out.println("数字字符的数量: "+digitCount);
	}
}

原文地址:https://www.cnblogs.com/wuyida/p/6300330.html