1用JAVA自帶的函數(shù)
2用正則表達(dá)式
public?static?boolean?isNumeric(String?str){
??for?(int?i?=?0;?i?<?str.length();?i++){
???System.out.println(str.charAt(i));
???if?(!Character.isDigit(str.charAt(i))){
????return?false;
???}
??}
??return?true;
?}
??for?(int?i?=?0;?i?<?str.length();?i++){
???System.out.println(str.charAt(i));
???if?(!Character.isDigit(str.charAt(i))){
????return?false;
???}
??}
??return?true;
?}
2用正則表達(dá)式
public?boolean?isNumeric(String?str){?
???Pattern?pattern?=?Pattern.compile("[0-9]*");?
???Matcher?isNum?=?pattern.matcher(str);
???if(?!isNum.matches()?){
???????return?false;?
???}?
???return?true;?
}?
???Pattern?pattern?=?Pattern.compile("[0-9]*");?
???Matcher?isNum?=?pattern.matcher(str);
???if(?!isNum.matches()?){
???????return?false;?
???}?
???return?true;?
}?