public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String intpatten="[0-9]";
String charpatten="[a-zA-Z]";
String signalpatten="\\W";
int intflag=0;
int charflag=0;
int signalflag=0;
String str=sc.next();
String[] strs = new String[str.length()];
for(int i=0;i
if(strs[i].matches(intpatten))
intflag++;
else if(strs[i].matches(charpatten))
charflag++;
else
signalflag++;
}
System.out.println("字符个数:"+charflag+" 数字个数"+intflag+" 非字符数:"+signalflag);
}
正则表达式做 看不懂追问
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String intpatten="[0-9]";
String charpatten="[a-zA-Z]";
String signalpatten="\\W";
int intflag=0;
int charflag=0;
int signalflag=0;
String str=sc.next();
String[] strs = new String[str.length()];
for(int i=0;i
if(strs[i].matches(intpatten))
intflag++;
else if(strs[i].matches(charpatten))
charflag++;
else
signalflag++;
}
System.out.println("字符个数:"+charflag+" 数字个数"+intflag+" 非字符数:"+signalflag);
}
输入的String .length 就是个数。字母和数字的区分在计算机中是有数字代表的。判读在不在这个范围内就行了。然后再取个数