那小数点算不算?如果也算的话就用转换长整型捕获错误的方法来判断,如下:
String s="3212323j2313";
System.out.print("ok!");
try{
Lont.parseLong(s);
}catch(Exception e){System.out.print("error!");}
如果小数点不算的话就有double,如下:
String s="3212323j2313";
try{
Default.parseDefault(s);
System.out.print("ok!");
}catch(Exception e){System.out.print("error!");}

解决方案 »

  1.   

    Check数字是吧。
    public static boolean isNum(String str) {
            String num = "0123456789";
            String tmpStr = str;
            if(tmpStr == null || tmpStr.length()==0){
                return false;
            }
            for ( int i = 0 ; i < tmpStr.length(); i++) {
                if (num.indexOf(tmpStr.substring(i, i+1)) < 0 ) {
                    return false;
                }
            }
            return true;
        }
      

  2.   

    beyond_xiruo:
        问个小问题,在实际做项目的时候,用这种方法也可以吗??会不会有什么不良后果呢?
      

  3.   

    public static boolean isNum(String str) {
         if(str == null || str.length() == 0){
              return false;
         }
         for ( int i = 0 ; i < tmpStr.length(); i++) {
             if (str.charAt(i) < '0' || str.charAt(i) > '9') {
                  return false;
             }
         }
         return true;
    }