Fix the code without changing what's in the test aka the main method? While also following the
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2 package main; 3 public class Lab09{ 40 public static void main(String[] args) { 5 // My tests (DO NOT MODIFY!) 6 int[] a = {3,2,6,4,15,7,9,8,6}; x 8 7 p(recurseSum (a)); // Sum should be 60 p(recurseMax (a)); // Max should be 15 9 // End of tests! 10 } 11 12 // TODO Auto-generated method stub 13 14 15 // Recursive methods below here... 160 public static int recurseSum(int[] a) { 17 return recurseSumHelper (a, 0); 18 } 190 private static int recurseSumHelper (int[] a, int index) { 20 // Base Case 21 if (index == a.length) { 22 return 0; 23 24 25 26 27 28 } 290 public static int recurseMax (int[] a) { 30 return recurseMaxHelper (a, 0, Integer.MIN_VALUE); } // Recursive Case else { return a[index] + recurseSumHelper (a, index + 1); } 31 } 320 private static int recurseMaxHelper (int[] a, int index, int maxValue) { 33 // Base Case 34 if (index == a.length) { 35 return maxValue; 36 37 38 39 40 41 // Recursive Case else { if (a[index] > maxValue) { maxValue = a[index]; 42 43 ΔΔ 2 } } return recurseMaxHelper (a, index + 1, maxValue); 2 package main; 3 public class Lab09{ 40 public static void main(String[] args) { 5 // My tests (DO NOT MODIFY!) 6 int[] a = {3,2,6,4,15,7,9,8,6}; x 8 7 p(recurseSum (a)); // Sum should be 60 p(recurseMax (a)); // Max should be 15 9 // End of tests! 10 } 11 12 // TODO Auto-generated method stub 13 14 15 // Recursive methods below here... 160 public static int recurseSum(int[] a) { 17 return recurseSumHelper (a, 0); 18 } 190 private static int recurseSumHelper (int[] a, int index) { 20 // Base Case 21 if (index == a.length) { 22 return 0; 23 24 25 26 27 28 } 290 public static int recurseMax (int[] a) { 30 return recurseMaxHelper (a, 0, Integer.MIN_VALUE); } // Recursive Case else { return a[index] + recurseSumHelper (a, index + 1); } 31 } 320 private static int recurseMaxHelper (int[] a, int index, int maxValue) { 33 // Base Case 34 if (index == a.length) { 35 return maxValue; 36 37 38 39 40 41 // Recursive Case else { if (a[index] > maxValue) { maxValue = a[index]; 42 43 ΔΔ 2 } } return recurseMaxHelper (a, index + 1, maxValue);
Expert Answer:
Answer rating: 100% (QA)
Here is the fixed code Java package main public class Lab09 public static void mainString args My te... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
Carol Harris, Ph.D, CPA, is a single taxpayer and she lives at 674 Yankee Street, Durham, NC 27409. Her Social Security number is 793-52-4335. Carol is an Associate Professor of Accounting at a local...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-6. On December 12, Irene purchased the building where her store is located. She paid...
-
Use the data in the table to complete the following. (a) Make a scatterplot of the data. Estimate a value for b so that f(x) = 0.0002x b models the data. (b) Check the accuracy of f(x). (c) The moon...
-
You have the following information for McBride Inc. for the month ended October 31, 2012. McBride uses a periodic method for inventory. Instructions(a) Calculate(i) Ending inventory ,(ii) Cost of...
-
A commercial process for preparing ethanol (ethyl alcohol), C2H5OH, consists of passing ethylene gas, C2H4, and steam over an acid catalyst (to speed up the reaction). The gas-phase reaction is...
-
A lamp flashes at the origin. Then, \(1 \mu\) s later, a lamp flashes at a point \(150 \mathrm{~m}\) from the origin. How fast, as a fraction of \(c\), would an astronaut need to travel so that he...
-
On January 1, Year 3, the Most Company purchased 80% of the outstanding voting shares of the Least Company for $1.6 million in cash. On that date, Leasts balance sheet and the fair values of its...
-
What are three expenses that you changed in the Perez family spending plan after the accident? * Identify the impact eliminating/reducing each of these expenses will have on the family. What...
-
Should Grand Central Publishing continue to bid for Dewey, wait for the scheduled auction with several interested publishers, or pull out of the race? Why? 2. What is the role of authors, agents, and...
-
The following is the trail Balance of X and Y Co. as on March 31, 2021. The partners sharing profits and losses in the ratio 2:1. Prepare the Income Statement, Profit & Loss Appropriation A/c,...
-
A currFutures Contract is an agreement to trade an asset on some future date at a price that is locked in today. ency forward is a customized, written contract between two parties that sets a fixed...
-
Question a In chapter 14, we learn about the fraud triangle. Research the "fraud triangle". Do you think fraud can still occur if one of the elements of the fraud triangle is not present? Explain....
-
Two mining fields, Field A and Field B, of a coal mining company produce Lignite and Bituminous coal. The operating cost per day for Field A and Field B are $55,000 and $45,000, respectively. The...
-
A small object is projected from level ground with an initial velocity of magnitude 18.0 m/s and directed at an angle of 60.0 above the horizontal. Part A What is the horizontal displacement of the...
-
Faculty of Management, Law and Social Sciences Assessment Information Form DEPARTMENT Accounting, Finance and Economics MODULE TITLE Empirical Methods in Accounting and Finance MODULE CODE AFE6014-B...
-
The images of the standard basis vectors for R for a linear transformation T: R R are: -> 0 T(e) = [3]. T 5 X= T(e) = ? ? ? 4(H) A = ? ? ? ? ? ? Find the standard matrix A for the transformation, and...
-
A city maintains a solid waste landfill that was 12 percent filled at the end of Year 1 and 26 percent filled at the end of Year 2. During those periods, the government estimated that total closure...
-
Assume we have a very simple message digest. Our unrealistic message digest is just one number between 0 and 25. The digest is initially set to 0. The cryptographic hash function adds the current...
-
Using RFC 1939, assume a POP3 client is in the download-and-delete mode. Show the transaction between the client and the server if the client has only two messages of 230 and 400 bytes to download...
-
A program to change an address in any notation to two other notations.
-
List the most important three factors for you personally when deciding where to shop for clothes.
-
List all of the factors you can think of that people use when deciding where to shop for clothes.
-
Describe the car you, a friend, or family member had at age 30. a. What were the top two reasons this car was bought? b. What was the trigger for this purchase?
Study smarter with the SolutionInn App