Chinaunix首页 | 论坛 | 博客
  • 博客访问: 222012
  • 博文数量: 81
  • 博客积分: 1165
  • 博客等级: 少尉
  • 技术积分: 1425
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-04 11:27
文章分类

全部博文(81)

文章存档

2015年(1)

2014年(2)

2013年(37)

2012年(41)

我的朋友

分类: Java

2013-07-30 16:58:49


 
1用JAVA自带的函数
public static boolean isNumeric(String str){
  
for (int i = str.length();--i>=0;){   
   
if (!Character.isDigit(str.charAt(i))){
    
return false;
   }
  }
  
return true;
 }

2用正则表达式
public static boolean isNumeric(String str){
    Pattern pattern = Pattern.compile("[0-9]*");
    return pattern.matcher(str).matches();   
 }

3用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;
}
阅读(783) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~