Unexpected java.util.Scanner behaviour
Is it just me or do others find the following behaviour strange? It seems that in order to break out of the loop in the following, it's necessary to enter some character(s) unparseable as a double. Hitting return *won't* cause it to break:
publicstaticvoid scanInts(String[] args){
Scanner scanner =null;
List<Double> coefficients =new ArrayList<Double>();
double x = Double.NaN;
try{
scanner =new Scanner(System.in);
while(scanner.hasNextDouble()){
double d = scanner.nextDouble();
System.out.println("double=" + d);
coefficients.add(d);
}
System.out.println("Now out of loop");
}
finally{
System.out.println(coefficients);
scanner.close();
}
}

