import java.util.Scanner;
public class Unit2Err2{
public static void main( String[] args ){
Scanner scan = new Scanner(System.in);
double sum = 0;
double count = 0;
double in = scan.nextDouble();
while (scan.nextDouble()!= 0){
sum = sum + in;
count++;
}
double avg= sum/count;
System.out.println("The average is " +avg);
}
}
Input: 5 4 3 0 6 4 3
In particular I don't have any errors, I did have a error which said: incomparable types: boolean and int. But I fixed it, my issue now is that the average should be 4 instead of 5. I'm wondering where the error is in this, I have tried rearranging it so my average comes out to 4 , but then I often end up with the same error as above.
double in = scan.nextDouble(); while (scan.nextDouble()!= 0){Since Your are not reassigning Theinis 5 and condition checks for next double so for input5 4 3 0 6 4 3here is the value that gets added for corresponding input in bracket 5 + 5(4) + 5(3) + 5(6) + 5(4) + 5(3) so its 30/6 hence your are getting 5.