What i am trying to do is use a while loop to check if int number is positive or negative and depending if such number is positive or negative execute the relevant code. The user is going to keep putting in numbers until they enter a negative number and once they do that the while loop will exit and it will print out the average of all the positive numbers before that negative number was typed in. I was trying to get int number to be reassigned each time the user puts in a number.
this is my code:
import java.util.*;
public class Question7{
public static void main (String [] args){
int number=0;
int average=0;
int counter=0;
int sum=0;
Scanner sc = new Scanner(System.in);
number = sc.nextInt();
while (number > 0) {
counter++;
sum = sum + number;
average= sum/counter;
}
System.out.println("this is the average:" + average);
}
}