输入一个字符串,统计其中纯字母串,纯数字串和其他串的个数

例如: “aaa 888 a88 a uus88,ss”

纯字母串为:3  

纯数字串为:1

其它串为:2

public class Test04 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String s = "aaa 888 a88 a uus88,ss";
		String[] arr = s.split("[ ,]");		
		int a=0,b=0,c=0;
		for (String str : arr) {
			if(str.matches("[a-zA-Z]{1,}")) {
				a++;
			}else if(str.matches("[0-9]{1,}")) {
				b++;
			}else{
				c++;
			}
		}
		System.out.println(a + "," + b + "," + c);
	}

}

猜你喜欢

转载自blog.csdn.net/weixin_39788493/article/details/80737101