Question
Write a program that reads in lines from the input. For every line, it reads in the numbers in the line and then prints their
Write a program that reads in lines from the input. For every line, it reads in the numbers in the line and then prints their sum, average, min, and max
Note that this problem is an advanced version on 006 Three Numbers problem. Input The format of an input line is k input1 input2 input3 inputk where k is an integer and input1, input2, etc are all real numbers. Note there are k real numbers on the line. The first integer in the line, i.e. k, is the number of real numbers that will be supplied in that line.
Output:
Each line of output consists of the sum, the average, the min, and the max of the k real numbers on the line. These are printed using %10.2f format and are separated by a single space.
Sample Input:
5 1.0 2.0 3.0 4.0 5.0
11 51.94 96.63 27.05 48.42 95.97 81.35 59.3 28.01 44.29 35.9 68.56
1 55.22
Sample Output:
15.00 3.00 1.00 5.00
637.42 57.95 27.05 96.63 55.22
55.22 55.22 55.22
HINT
1. To find max and min see section 4.5.4 (page 149) of text book.
2. Instead of setting the largest to in.nextDouble() at the beginning set double largest = Double.MIN_VALUE; Similarly, set double smallest = Double.MAX_VALUE; at the beginning. Rest will be similar.
3. First read the integer k. Then, LOOP k times each time reading a number and adding to the sum, fixing the max and the min. After reading all the k items, you can compute the average (sum/k) and print using the correct format.
4. To print, use System.out.printf("%10.2f", sum); etc
I have made my code however is is not working. What do I need to change?
File Edit Source Refactor Navigate Search Project Run Window Help Quick Access CountUpperCasejavaManyNumbersjaa-RealEquity jiava 1 import java.util.; 2 public class Manylumbers 3public static void main Strin8) args) double largest-Double.MIN VALUE, smallest-Double.MAX VALUE,sum-0,avg-0; int k; Scanner scnew Scanner(System.in); k-sc.nextInt); double] doublearrnew double[k]; for(int i-0;iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started