1用JAVA自帶的函數
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;
?}
2用正則表達式
public?boolean?isNumeric(String?str){?
???Pattern?pattern?=?Pattern.compile("[0-9]*");?
???Matcher?isNum?=?pattern.matcher(str);
???if(?!isNum.matches()?){
???????return?false;?
???}?
???return?true;?
}?
posted on 2006-07-03 15:58
一凡 閱讀(1813)
評論(0) 編輯 收藏 所屬分類:
JAVA 基礎