readLine problem
Hi guys,
I have a slight problem here. My code is simple and is as follows:
import java.io.*;
public class Average {
public static void main(String[] args) throws IOException {
double numbers = 0.0;
System.out.println("Please enter 5 numbers");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (int i=0; i<5; i++) {
numbers += Double.parseDouble(br.readLine());
}
System.out.println("The average of your numbers is " + numbers/5);
}
}
My problem is that readLine keeps remembering the very first double read. For example, if I input, 1,2,3,4,5, I get an average of 1.0
This is obviously wrong, but it is because the first time I enter 1, the program remembers that and always goes 1+1+1+1+1. Which is why I get and average of 1.0
Strange thing is that if I put System.out.println("") after the line in the for loop, it works.
Any ideas?
Thanks

