subject

Translate the following sum function from iterative to

* recursive.

*

* You should write a helper method. You may not use any "fields" to solve

* this problem (a field is a variable that is declared "outside" of the

* function declaration --- either before or after).

*/

public static double sumIterative (double[] a) {

double result = 0.0;

int i = 0;

while (i < a. length) {

result = result + a[i];

i = i + 1;

}

return result;

}

public static double sum (double[] a) {

return 0; // TODO

}

/**

* PROBLEM 2: Do the same translation for this in-place reverse function

*

* You should write a helper method. You may not use any "fields" to solve

* this problem (a field is a variable that is declared "outside" of the

* function declaration --- either before or after).

*/

public static void reverseIterative (double[] a) {

int hi = a. length - 1;

int lo = 0;

while (lo < hi) {

double loVal = a[lo];

double hiVal = a[hi];

a[hi] = loVal;

a[lo] = hiVal;

lo = lo + 1;

hi = hi - 1;

}

}

public static void reverse (double[] a) {

// TODO

}

/**

* @param args

*/

public static void main (String[] args) {

double[] list0 = new double[] {};

double[] list1 = new double[] { 5 };

double[] list2 = new double[] { -3, 5 };

double[] list3 = new double[] { 2, -3, 5 };

double[] list4 = new double[] { -1, 2, -3, 5 };

double[] list5 = new double[] { 33, 44, 55 };

System. out. println("Display the sum of the array contents");

System. out. println ("list5: " +sum (list5));

System. out. println ("list0: " +sum (list0));

System. out. println ("list1: " +sum (list1));

System. out. println ("list2: " +sum (list2));

System. out. println ("list3: " +sum (list3));

System. out. println ("list4: " +sum (list4));

System. out. println("Reversing the lists");

reverse (list0);

System. out. println ("list0: " +Arrays. toString (list0));

reverse (list1);

System. out. println ("list1: " +Arrays. toString (list1));

reverse (list2);

System. out. println ("list2: " +Arrays. toString (list2));

reverse (list3);

System. out. println ("list3: " +Arrays. toString (list3));

reverse (list4);

System. out. println ("list4: " +Arrays. toString (list4));

reverse (list5);

System. out. println ("list5: " +Arrays. toString (list5));

}

}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 22:00
Researchers measured the data speeds for a particular smartphone carrier at 50 airports. the highest speed measured was 78.1 mbps. the complete list of 50 data speeds has a mean of x overbarequals16.11 mbps and a standard deviation of sequals18.65 mbps. a. what is the difference between carrier's highest data speed and the mean of all 50 data speeds? b. how many standard deviations is that [the difference found in part (a)]? c. convert the carrier's highest data speed to a z score. d. if we consider data speeds that convert to z scores between minus2 and 2 to be neither significantly low nor significantly high, is the carrier's highest data speed significant? a. the difference is nothing mbps.
Answers: 3
question
Computers and Technology, 23.06.2019 13:30
What is the primary difference between the header section of a document and the body? a. the body is displayed on the webpage and the header is not. b. the header is displayed on the webpage and the body is not. c. the tag for the body is self-closing, but the tags for the headers must be closed. d. the tag for the header is self closing, but the tag for the body must be closed.
Answers: 3
question
Computers and Technology, 23.06.2019 21:00
Which set of steps will organize the data to only show foods with more than 100 calories and rank their sugar content from greatest to least?
Answers: 1
question
Computers and Technology, 24.06.2019 00:00
Consider the series where in this problem you must attempt to use the ratio test to decide whether the series converges. compute enter the numerical value of the limit l if it converges, inf if it diverges to infinity, minf if it diverges to negative infinity, or div if it diverges but not to infinity or negative infinity.
Answers: 1
You know the right answer?
Translate the following sum function from iterative to

* recursive.

*
<...
Questions
question
History, 25.06.2020 05:01
question
Mathematics, 25.06.2020 05:01
question
Mathematics, 25.06.2020 05:01
question
Mathematics, 25.06.2020 05:01
Questions on the website: 13722360