Question: Write TWO recursive methods. One to find the maximum in an array, the other to find the minimum. JAVA public class Lab { public static
Write TWO recursive methods. One to find the maximum in an array, the other to find the minimum. JAVA
public class Lab { public static void main (String []args) { int A[] = {2,5,7,-4,6,3}; System.out.println(FindMax(A,5)); //n is the index of the last element in the array System.out.println(FindMin(A,5)); } public static int FindMax(int A[], int n) //n is the index of the last element in the array
//need help here { if (n<1){ return A[0]; } if (FindMax(A, n-1)> A[n]){ return 1; } else { return A[n]; } } public static int FindMin(int A[], int n) //n is the index of the last element in the array
//need help here { if (n<1){ return A[0]; } if (FindMin(A, n-1)> A[n]){ return 1; } else { return A[n]; } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
