i need this for java it needs to ask how many inputs to take in and then get the
ID: 3646405 • Letter: I
Question
i need this for java it needs to ask how many inputs to take in and then get the sum average and high and lowest numberWrite an application program that reads in a list of integer numbers and print out the sum of all numbers, the average, the lowest and the highest value entered. The first input number indicates how many numbers the program is going to read. For example, if the first number entered is 5, then it means five integer numbers will be expected as input. Display your result in an output dialog box.
Run/test you program with at least 5 input numbers.
Explanation / Answer
import java.io.*;
import javax.swing.JOptionPane;
class Array
{
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
String firstNumber;
int size,sum=0;
double average=0;
firstNumber = JOptionPane.showInputDialog ( "Enter the number of integers" );
size=Integer.parseInt ( firstNumber);
int a[]=new int[size];
System.out.println("Enter values");
for(int i=0;i<sizei++)
a[i]=scan.nextInt(System.in);
int min=a[i],max=a[i];
for(i=0;i<size;i++)
{
sum=sum+a[i];
if(a[i]<min)
min=a[i];
if(a[i]>max)
max=a[i];
}
average=(sum/size);
JOptionPane.showMessageDiallog(null,"result:"+sum+min+max+average);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.