Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Fix the code without changing what's in the test aka the main method? While also following the instructions provided. 2 package main; 3 public class
Fix the code without changing what's in the test aka the main method? While also following the instructions provided.
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);
Step by Step Solution
★★★★★
3.27 Rating (150 Votes )
There are 3 Steps involved in it
Step: 1
Here is the fixed code Java package main public class Lab09 public static void mainString args My te...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started