java没有提供可以直接从键盘读入数字值的方法,象你这么做,读入的是字符的ASCII码。
可以用类型包装器(Integer、Double、Float等)来转换,具体做法如下:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s1;
String s2;
System.out.println("Enter a int data: ");
s1 = br.readLine();
int i = Integer.parseInt(s1);
System.out.println("Enter a double data: ");
s2 = br.readLine();
double d = Double.parseDouble(s2);
System.out.println("i = " + i);
System.out.println("d = " + d);

解决方案 »

  1.   

    java没有提供可以直接从键盘读入数字值的方法,象你这么做,读入的是字符的ASCII码。
    这个问题我以前都碰到过,现在看来可以用Datatype Wrapper搞定了
      

  2.   

    看版主吧,已经解决了。还有好像DatatInputStream只有如下方法,没有read()方法哦。
    boolean readBoolean() 
              Reads one input byte and returns true if that byte is nonzero, false if that byte is zero. 
     byte readByte() 
              Reads and returns one input byte. 
     char readChar() 
              Reads an input char and returns the char value. 
     double readDouble() 
              Reads eight input bytes and returns a double value. 
     float readFloat() 
              Reads four input bytes and returns a float value. 
     void readFully(byte[] b) 
              Reads some bytes from an input stream and stores them into the buffer array b. 
     void readFully(byte[] b, int off, int len) 
              Reads len bytes from an input stream. 
     int readInt() 
              Reads four input bytes and returns an int value. 
     String readLine() 
              Reads the next line of text from the input stream. 
     long readLong() 
              Reads eight input bytes and returns a long value. 
     short readShort() 
              Reads two input bytes and returns a short value. 
     int readUnsignedByte() 
              Reads one input byte, zero-extends it to type int, and returns the result, which is therefore in the range 0 through 255. 
     int readUnsignedShort() 
              Reads two input bytes and returns an int value in the range 0 through 65535. 
     String readUTF() 
              Reads in a string that has been encoded using a modified UTF-8 format. 
     int skipBytes(int n)  
      

  3.   

    寒号不已的话差不多,不过我想读入的应是unicode,而非ascii。