I\'m getting error when i run this code need help cleaning it up Write an applic
ID: 3646425 • Letter: I
Question
I'm getting error when i run this code need help cleaning it upWrite 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.
import java.io.*;
import javax.swing.JOptionPane;
class test
{
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<size;i++)
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.showMessageDialog(null,"result:"+sum+min+max+average);
}
}
Explanation / Answer
for(int i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.