rt 3x!

解决方案 »

  1.   


    /**
     * 无异常的parseInt方法
     * @param s
     * @return
     */
    public static int parseInt(String s) {
        if (s == null) {
          return 0;
        }
        try {
          return Integer.parseInt(s);
        }
        catch (NumberFormatException nfe) {
          return 0;
        }
    }
      

  2.   

    int ia=0;
    String str="123";
    try
    {
      ia=Integer.parseInt(str);
    }catch{
       ia=0;
       System.out.println(str+"不是数字");
    }
      

  3.   

    不好意思,上面那个没有写完整
     int ia=0;
    String str="123";
    try
    {
      ia=Integer.parseInt(str);
    }catch(NumberFormatException e){
       ia=0;
       System.out.println(str+"不是数字");
    }
      
      

  4.   

    楼上的都可以,我也来写一种,
        public boolean  IsNumber(String str) 
        { 
        String number_chars = "1234567890"; 
        for (int i=0;i<str.length();i++) 
        { 
        if(number_chars.indexOf(str.charAt(i))==-1)
            return false; 
        } 
        return true; 
        }