Write a Java program to input the following integer numbers into an array named
ID: 3660063 • Letter: W
Question
Write a Java program to input the following integer numbers into an array named grades: 89, 95, 72, 83, 99, 54, 86, 75, 92, 73, 79, 75, 82, 73. As each number is input, add the number to a total. After all numbers are input and the total is obtained, calculate the average of the numbers and use the average to determine the deviation of each value from the average. Store each deviation in an array named deviation. Each deviation is obtained as the element values less the average of all the data. Have your program display each deviation alongside its corresponding element from the grades array.Explanation / Answer
please rate - thanks
import javax.swing.*;
public class main
{
public static void main(String []args)
{int total=0,n,i;
double average;
String input,output;
input= JOptionPane.showInputDialog(null,"How many numbers do you have? ");
n=Integer.parseInt(input);
int [] grades= new int[n];
double []deviation=new double[n];
for(i=0;i<n;i++)
{input= JOptionPane.showInputDialog(null,"Enter number "+(i+1)+": ");
grades[i]=Integer.parseInt(input);
total+=grades[i];
}
average=(double)total/n;
for(i=0;i<n;i++)
deviation[i]=grades[i]-average;
output=("element grade deviation ");
for(i=0;i<n;i++)
output=output+(i+1)+" "+grades[i]+" "+deviation[i]+" ";
JOptionPane.showMessageDialog(null,output);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.