String s="yg";
System.out.println(Integer.parseInt(s));会报java.lang.NumberFormatException: For input string: "yg"异常。
怎么对S进行预判断,保证S里面存的是数字类型的字符,可以paerInt();
不想用try做异常检测!

解决方案 »

  1.   

    用Asc码一个一个字符判断.或用正则表达式判断.
      

  2.   

        public boolean isNum(String str)
        {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if( !isNum.matches() )
        {
        return false;
        }
        return true;
        } 
      

  3.   

    谢谢
    LS俩位
    JAVA程序员正则表达示有必要精通么?