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

Let u be a one-dimensional array of type double that has been properly declared

ID: 671194 • Letter: L

Question

Let u be a one-dimensional array of type double that has been properly declared and initialized in the main(...)method (the public italic void main(...) method) Shown below is an example for such a declaration and initialization: In the main(...) method, use a Java loop to compute the sum of all element-, stored in u Define a method called getSum that takes an array of type double as a parameter, computes the sum of all elements stored in the array, and then returns the sum to the caller of the method Define a method called getHighest that takes an array of type double as a parameter. This method should return the highest values in the array to the caller of the method. In the main(...) method, write a single Java statement to print the sum and the highest value of all elements stored in u.

Explanation / Answer

public class SumArray1 { public static void main(String[] args) { double[] a = { 1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0,5.5,6.0 }; int i; // array index double sum; // Running sum for ( i = 0 ; i