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

The question states: Write a program that will contain at least 2 methods. One m

ID: 3635806 • Letter: T

Question

The question states: Write a program that will contain at least 2 methods. One method will initialize an array using JOptionPane. The array will be of type double and contain 25 elements. The second method will calculate the average of all the values in the array and print the average as well as the deviation of every value from the average.

I can't get my code to run here is what I have so far.

import javax.swing.JOptionPane;
import java.util.Arrays;
class Test3Q5
{
public static void main(String[]args)
{
String in;
double [] a = new double[24];
double x;
for (x=0;x<=24;++x)
{
in=JOptionPane.showInputDialog(null, "Enter A Value");
}
System.out.println (Arrays.toString(a));
System.out.println (a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9]+a[10]+a[11]+a[12]+a[13]+a[14]+a[15]+a[16]+a[17]+a[18]+a[19]+a[20]+a[21]+a[22]+a[23]+a[24]);
}
}
/*
Compiles but doesn't output my results
*/

Explanation / Answer

please rate - thanks

import javax.swing.JOptionPane;
import java.util.Arrays;
class Test3Q5
{
public static void main(String[]args)
{
String in;
double [] a = new double[24];
init(a);
average(a);
}
public static void init(double a[])
{String in;
int x;
for (x=0;x<24;++x)
{
in=JOptionPane.showInputDialog(null, "Enter A Value");
a[x]=Double.parseDouble(in);
}
}
public static void average(double a[])
{int i;
double sum=0,average;
for(i=0;i<24;i++)
    sum+=a[i];
average=sum/24.;
System.out.println("Average: "+average);
System.out.println("number value deviation from average");
for(i=0;i<24;i++)
   System.out.println((i+1)+" "+a[i]+" "+(average-a[i]));
}
}

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