Im trying to get this while loop to work. The program keeps asking for integers till a negative is entered then it prints out the average
I think the problem is in the while loop but im not sure. Any help?
I think the problem is in the while loop but im not sure. Any help?
public static void main(String[] args) {
int count = 0;
int sum = 0;
boolean finished = false;
while(!finished);{
Scanner myInput = new Scanner(System.in);
System.out.print("Enter an integer: ");
int n = myInput.nextInt();
if (n < 0)
finished = true;
else
sum = (sum + n);
count = count+1;
System.out.println(sum/count);
}