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??
![Enter program input (optional)
15 20 0 5-1
LabProgram.java
(Your program)
Run program
Input (from above)
Output (shown below)
Program output displayed here
17 2](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc00246d7-210d-47f4-964d-360b3bcbb90b%2Fd661aec6-ace0-4398-b72d-f9ca22eba276%2F9yk0tf_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)