随笔-204  评论-90  文章-8  trackbacks-0
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 一凡 阅读(1794) 评论(0)  编辑  收藏 所属分类: JAVA 基础

只有注册用户登录后才能发表评论。


网站导航: