Ask Question
7 August, 00:21

Statistics are often calculated with varying amounts of input data. Write a program that takes any number of integers as input, and outputs the average and max.

Ex: If the input is:

15 20 0 5

the output is:

10 20

+1
Answers (1)
  1. 7 August, 00:34
    0
    import java. util. Arrays;

    import java. util. Scanner;

    public class TestClock {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("How many numbers are you dealing with");

    int numList = in. nextInt ();

    int []numArray = new int[numList];

    for (int i=0; i
    System. out. println ("Enter the values");

    numArray[i] = in. nextInt ();

    }

    //Finding average

    int sum = 0;

    for (int i=0; i
    sum = sum+numArray[i];

    }

    int average = sum/numList;

    //Finding the maximum

    int max = numArray[0];

    for (int i = 0; i
    if (numArray[i]>max) {

    max = numArray[i];

    }

    }

    System. out. println (Arrays. toString (numArray));

    System. out. println (max+" "+average);

    }

    }

    Explanation:

    Create an array to hold the values to be entered by the user Using a for statement sum up the elements of the array and find their average Using another for loop find the maximum value in the array Output the array Output the maximum and average
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Statistics are often calculated with varying amounts of input data. Write a program that takes any number of integers as input, and outputs ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers