xt 发帖数: 17532 | 1
This is because DataInputStream is used to read in binary data,
not text data. You need to do sth like this:
//suppose you input 1 number a time, otherwise please use
//StringTokenizer after reading in the line string.
float x = 0.0;
String line = null;
try {
line = System.in.readLine();
}catch (IOException e) {
}
if (line!=null && line.length>0) {
try {
x = Float.parsefloat(line);
} catch (NumberFormatException e) {
}
} |
|