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

Write a Java program that asks a user to input a number of values of type double

ID: 3619995 • Letter: W

Question

Write a Java program that asks a user to input a number of values of type double and then prints:

the average of the values
the smallest of the values
the largest of the values
the range, that is, the difference between the smallest and the largest of the values
The user is allowed to enter either positive or negative values. An entry of "end" or "stop" indicates there are no more values to be input.
Use a loop to repeatedly ask a user for input values. To get the inputs, I suggest you use JOptionPane, which returns a String. Test the String for the stopping words and, if there is no match, assume the input is a number of type double. Convert the String to a double using
double value = Double.parseDouble(input) no arrays, just using loops.
double value = Double.parseDouble(input) no arrays, just using loops.

Explanation / Answer

please rate - thanks import java.util.*;
import javax.swing.*;
public class numbers
{
public static void main(String []args)
{String input,message;
double value,average,large=-9999999,small=9999999,range,sum=0;
int i=0;
System.out.println("The values you entered");
input = JOptionPane.showInputDialog(null, "Enter a number (end to exit): ");
while(input.compareTo("end")!=0)
   {System.out.print(input+" ");
   i++;
   value=Double.parseDouble(input);  
   sum+=value;
   if(value<small)
        small=value;
   if(value>large)
        large=value;  
   input = JOptionPane.showInputDialog(null, "Enter a number (end to exit): ");
   }
average=sum/i;
range=large-small;
System.out.println(" the average of the values: "+average);
System.out.println("the smallest of the values: "+small);
System.out.println("the largest of the values: "+large);
System.out.println("the range of the values: "+range);
}
}
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote