import java.util.*;
public class Average {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
int next = 0;
int total = 0;
int counter = 0;
do {
counter++ ;
System.out.println("Type a Number: ");
next = console.nextInt();
total = next + total ;
}
while(next >= 0);
System.out.println("average is " + (total / counter));
}
}
trying to use a while loop to add x amount of integers but when a negative number is inputted the loop stops and prints the average of the numbers that you have entered

New Topic/Question
Reply


MultiQuote




|