IN JAVA Complete the following program. Add codes in the main method to:1) call method average(double[] gpaarr ) to calculate the average of gpaArray; 2) add codes in the for loop to calculate sum
3) print the average .
public class Test {
public static void main (String args[]) {
double[ ] gpaArray = { 2.5, 4.0, 3.8, 3.2, 2.9, 4.0 } ;
//add your codes here (you can put your codes in the Answer area with/without copying the original codes)
}
public static double average (double gpaarr)
{
double average = 0.0;
double sum = 0.0;
//find sum of all the elements
for(int i = 0; i< gpaarr.length; ++i)
{
//add your codes here (you can put your codes in the Answer area with/without copying the original codes)
}
average = sum/ gpaarr.length;
return average;
}
}//end of class Test
public class Test { public static void main (String args[]) { double[ ] gpaArray = { 2.5, 4.0, 3.8, 3.2, 2.9, 4.0 } ; //add your codes here (you can put your codes in the Answer area with/without copying the original codes) System.out.println(average(gpaArray)); } public static double average (double gpaarr[]) { double average = 0.0; double sum = 0.0; //find sum of all the elements for(int i = 0; i< gpaarr.length; ++i) { sum = sum + gpaarr[i]; //add your codes here (you can put your codes in the Answer area with/without copying the original codes) } average = sum/ gpaarr.length; return average; } }//end of class Test
3.4
Get Answers For Free
Most questions answered within 1 hours.