Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

- Show the average with four decimal places, using the DecimalFormatter class. -

ID: 3668317 • Letter: #

Question

- Show the average with four decimal places, using the DecimalFormatter class. - Trailing zeroes will not be shown.
If the user enters a zero, stop asking for inputs and output the minimum, maximum, and average of the values that have been entered prior to that point. - If the first input is zero, output an error message.
You may assume that the user will enter only valid integer values.
Sample runs below. Command Prompt c:test> c: est c: Itest>javac extremes.java c: est javac extremes java c: estjava extremes Enter up to ten integers. To stop before ten, enter a zero. ext input: 10 ext input: 20 ext input: 30 ext input: 0 The minimum is 10 The maximum is 30 The average is 20 c: est>java extremes Enter up to ten integers. To stop before ten, enter a zero. ext input: 1 ext input: 3 ext input: 9 ext input: 0 he minimum is 1 The maximum is 9 The average is 4. 3333 c: test

Explanation / Answer

import java.io.*;
import java.text.*;
public class Extremes
{
public static void main(String[] args)
{
int small=0,large=0,count=0;
int[] num = new int[10];// set up array of 10
for (int i = 0; i < 10; i++) // read in 10 numbers
{
System.out.println("Enter a number."); // get a number
int x; // number you entered

try
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
x = Integer.parseInt(s);
if(x==0)
System.out.println("PLEASE ENTER INTEGER VALUES");
while (x!=0)
{
num[i] = x; // put the number in the array
int sum=sum+x;
count++;
if (x>large)
large = x;
else (x<small)
{
small= x;
}
System.out.println("The MINIMUM VALUE IS"+small);
System.out.println("The MAXIMUM VALUE IS"+ large);
double avg=sum/count;//avg value is double type
if(avg%10==0)
int avg1=avg.intValue();//converting double type to integer type
System.out.println("The Average is"+avg1);
else
DecimalFormat myFormatter = new DecimalFormat(00.0000);
//setting number format using DecimalFormat class
String output = myFormatter.format(avg);
System.out.println("The Average is"+avg);

}

}
}
catch(IOException e)
{
x = 0;
}


}
}