When the character input part of the following code is set to BufferedReader, it cannot be input normally. Why? Works fine with Scanner
BufferedReader br = new
BufferedReader(newInputStreamReader(System.in));
double max = Double.NEGATIVE_INFINITY;
double min = Double.POSITIVE_INFINITY;
double dat = 0;
System.out.println(max + " " + min);
for(int i = 0;i < 4;i++) {
System.out.println("Numerical input");
dat = br.read(); //here
if(dat > max) {
max = dat;
}
if(dat < min) {
min = dat;
}
}
System.out.println("Maximum value:" + max + " " + "minimum value:" +min);
}
Execution result when using BufferedReader ↓
-Infinity Infinity Numerical input 1 Numerical input Numerical input Numerical input 2 Maximum value: 50.0 Minimum value: 10.0
Recommended Posts