private boolean isNumeric(String str){
Pattern pattern = ("[0-9]*$");
Matcher isNum = (str);
if( !() ){
return false;
}
return true;
}
二、使用异常报错:
public static boolean isNumeric00(String str){
try{
(str);
return true;
}catch(NumberFormatException e){
("异常:\"" + str + "\"不是数字/整数...");
return false;
}
}
三、 判断ASCII码值:
public static boolean isNumeric0(String str){
for(int i=();--i>=0;){
int chr=(i);
if(chr<48 || chr>57)
return false;
}
return true;
}
四、用JAVA自带的函数:
public static boolean isNumeric(String str){
for (int i = 0; i < (); i++){
((i));
if (!((i))){
return false;
}
}
return true;
}
方法一,个人认为比较好,使用灵活,正则表达式,可以修改,匹配各种想要的类型。