try{
    System.out.println("请输入一个整形数");
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    s=br.readLine();
    i=Integer.parseInt(s);
catch(IOException e){}

解决方案 »

  1.   

    System.out.print ("输入第一个数:");
    i = System.in.read ();
    while (i != 13)
    {
    if (((i >= 48) && (i <= 57)) || i == 46)
    {
    strTmp += (char) i;
    } i = System.in.read ();
    }
      

  2.   

    http;//j.topcool.net/ittraining/ittraining1.htm
      

  3.   


    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    import java.lang.NumberFormatException;/**
     * <p>Title: Pack standard input </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: Jinfonet </p>
     * @author zhijun.wu
     * @version 1.0
     */public class StandardInputReader {
        private static BufferedReader reader = new BufferedReader(
            new InputStreamReader(System.in));
           
           /**
         * Read a boolean value from standard input stream.
         *
         * @return a boolean value.
         * @throws IOException
         */
        public static boolean readBoolean() throws IOException {
            String strBoolean = reader.readLine();//        return Boolean.valueOf(strBoolean).booleanValue();
            if (strBoolean.equalsIgnoreCase("true")) {
                return true;
            } else if (strBoolean.equalsIgnoreCase("false")) {
                return false;
            } else {
                throw new NumberFormatException("For input string: \""
                                                + strBoolean +"\"");
            }
        }    /**
         * Read a byte value from standard input stream.
         *
         * @return a byte value.
         * @throws IOException
         */
        public static byte readByte() throws IOException {
            return Byte.parseByte(reader.readLine());
        }    /**
         * Read a short value from standard input stream.
         *
         * @return a short value.
         * @throws IOException
         */
        public static short readShort() throws IOException {
            return Short.parseShort(reader.readLine());
        }    /**
         * Read a int value from standard input stream.
         *
         * @return a int value.
         * @throws IOException
         */
        public static int readInt() throws IOException {
            return Integer.parseInt(reader.readLine());
        }    /**
         * Read a long value from standard input stream.
         *
         * @return a long value.
         * @throws IOException
         */
        public static long readLong() throws IOException {
            return Long.parseLong(reader.readLine());
        }    /**
         * Read a float value from standard input stream.
         *
         * @return a float value.
         * @throws IOException
         */
        public static float readFloat() throws IOException {
            return Float.parseFloat(reader.readLine());
        }    /**
         * Read a double value from standard input stream.
         *
         * @return a double value.
         * @throws IOException
         */
        public static double readDouble() throws IOException {
            return Double.parseDouble(reader.readLine());
        }
        
        /**
         * Read a line of text.  A line is considered to be terminated by any one
         * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
         * followed immediately by a linefeed.
         *
         * @return     A String containing the contents of the line, not including
         *             any line-termination characters, or null if the end of the
         *             stream has been reached
         *
         * @exception  IOException  If an I/O error occurs
         */
        public static String readLine() throws IOException {
         return reader.readLine();
        }  
    }