JAVA中怎么判断一个数组中所有元素的数据类型?

2024-11-15 14:41:02
推荐回答(1个)
回答(1):

import java.util.Scanner;

public class Java71 {

public static void main(String[] args) {
// TODO code application logic here
Scanner s = new Scanner(System.in);
System.out.println("请输入字符串:");
String a = s.nextLine();
int abccount = 0;
int numcount = 0;
int spacecount = 0;
int othercount = 0;
char[] b = a.toCharArray();
for(int i = 0; i < b.length; i++){
if(b[i]>='a'&&b[i]<='z'||b[i]>='A'&&b[i]<='Z'){
abccount++;
}else if(b[i]>='0'&&b[i]<='9'){
numcount++;
}else if(b[i]==' '){
spacecount++;
}else{
othercount++;
}
}
System.out.println("字符串中含有的英文字母数为:" + abccount);
System.out.println("字符串中含有的数字数为:" + numcount);
System.out.println("字符串中含有的空格数为:" + spacecount);
System.out.println("字符串中含有的其他字符为:" + othercount);
}
}