23.5k views
4 votes
Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative integers as input, and outpu

2 Answers

8 votes

Answer:hi

Step-by-step explanation:

User Nikhil Pathania
by
5.1k points
13 votes

Answer:

Step-by-step explanation:

The following program is written in Java and is a function that asks the user for an input and keeps doing so until a negative value is entered, in which case it calculates the average and max values and prints it to the screen.

public static void average () {

int num;

int sum = 0;

Scanner in = new Scanner(System.in);

System.out.println("Enter Number");

num = in.nextInt();

int count = 0;

int max = 0;

while(num >= 0)

{

sum+=num;

System.out.println("Enter Number");

num = in.nextInt();

count++;

if(num>=max){

max = num;

}

}

System.out.println(sum/count);

System.out.println(max);

}

User Omar Shawky
by
5.4k points