或者麻烦点的:new Integer("123").parseInt()

解决方案 »

  1.   

    Integer.parseInt("123"); 不需要创建一个对象
    new Integer("123").parseInt() 需要先创建一个对象,太浪费了
      

  2.   

    记住要try{}catch(NumberFormatException e){}
      

  3.   

    呵呵,这些常规处理java很简单的。
      

  4.   

    import java.io.*;
    public class IntRead {
    public  int intread(){
    int x=0;
    try{
    InputStreamReader stdin=new InputStreamReader(System.in);
    BufferedReader bufin=new BufferedReader(stdin);x=Integer.parseInt(bufin.readLine());}
    catch(Exception e){
    System.out.println(e);
    }
    return x;
    }
    }你只要把上面这个类IMPORT进去,用IntRead这个方法就行了。
      

  5.   

    import java.io.*;
    public class iread {
    public  int intread(){
    int x=0;
    try{
    InputStreamReader stdin=new InputStreamReader(System.in);
    BufferedReader bufin=new BufferedReader(stdin);x=Integer.parseInt(bufin.readLine());}
    catch(Exception e){
    System.out.println(e);
    }
    return x;
    }
    }
    你只要把上面这个类IMPORT进去,用intread这个方法就行了。 
      

  6.   

     /**
     * 将字符串转化成数字
     *
     * @paramter String 数字字符串
     * @return int
     */
      public int stringToInt(String s)
       {
         try
          {
            int i = Integer.parseInt(s);
            return i;
          }
          catch(Exception _ex)
          {
             return 0;
          }
       }
      

  7.   

    回复人: simoncn(早睡早起精神好) (  ) 信誉:100  2001-10-24  6:02:52  得分:0  
     
     
      Integer.parseInt("123");  不需要创建一个对象  
    new  Integer("123").parseInt()  需要先创建一个对象,太浪费了
    //==========================================================hehe...Integer中根本没有无参数的parseInt()....
     
     
      

  8.   

    system.in.read()不可以那么可以用readInt()嘛;楼上说的是对的,new Integer("123").intValue() 才正确,不过要new一个对象来转换是浪费了一点资源。
      

  9.   

    也可以 Integer.valueOf("123").intValue();
    呵呵~~