Write a method name maxElement, which returns the largest value
in an array that is passed as an argument. The method must
use recursion to find the largest element.
Demonstrate the method in a program. Write the JAVA
CODE on the paper that is provided.
(Put your name on every piece of paper) Use the following array to
test the method.
Int [] numbers = {2,12,1999,99,100,4,7,300}
PROGRAMMING LANGUAGE- JAVA.
Please answer the question ASAP. Thanks in advance!
// TestCode.java public class TestCode { public static int maxElement(int[] A, int high, int low) { if(high==low){ return A[high]; } else{ int max = maxElement(A,high+1,low); if(max < A[high]){ return A[high]; } else{ return max; } } } public static void main(String args[]) { int [] numbers = {2,12,1999,99,100,4,7,300}; System.out.println(maxElement(numbers,0,numbers.length-1)); } }
1999
Get Answers For Free
Most questions answered within 1 hours.