1. 程式人生 > >JAVA判斷字串是否為數字或者是否以0開頭

JAVA判斷字串是否為數字或者是否以0開頭

public static boolean isNumeric(String str){
if(str.matches("\\d*"){
return true;
}else{
return false;
}
}
4.用ascii碼
public static boolean isNumeric(String str){
for(int i=str.length();--i>=0;){
int chr=str.charAt(i);
if(chr<48 || chr>57)
return false;
}
return true;
}