Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative integers as input, and outputs the average and max. A negative integer ends the input and is not included in the statistics. Ex: When the input is: 15 20 0 5 -1 the output is: 10 20 You can assume that at least one non-negative integer is input. import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int numValue; int average; int max; int numValues; int numTotal; numTotal = 0; numValues = 0; max = 0; numValue = scnr.nextInt(); while (numValue > 0){ numTotal = numTotal + numValue; numValues = numValues + 1; numValue = scnr.nextInt(); } average = numTotal / numValues; System.out.print(average); while (numValues > max){ max = numValues; System.out.print(" " + max); } } } Why is it giving me the wrong output??
Statistics are often calculated with varying amounts of input data. Write a
Ex: When the input is:
15 20 0 5 -1
the output is:
10 20
You can assume that at least one non-negative integer is input.
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int numValue;
int average;
int max;
int numValues;
int numTotal;
numTotal = 0;
numValues = 0;
max = 0;
numValue = scnr.nextInt();
while (numValue > 0){
numTotal = numTotal + numValue;
numValues = numValues + 1;
numValue = scnr.nextInt();
}
average = numTotal / numValues;
System.out.print(average);
while (numValues > max){
max = numValues;
System.out.print(" " + max);
}
}
}
Why is it giving me the wrong output??
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images