How do I make a recursive method for finding the largest element in an array A of N elements?

I need to know how to start a program that uses a recursive method in order to find the largest element in an array A of N elements.
Who is Participating?
try something like:

public int largest(int[] array)
   return largest(array, 0);

int largest(int[] array, int start)
   if (start==array.length-1) return array[start];
   else return Math.max(array[start], largest(array, start+1);

You can use something like this:

int max(int[] A) {
      return max(A, 0, -Integer.MAX_VALUE);

int max(int[] A, int start, int max) {
      if(start>=A.legnth) {
            return max;
      if(A[i]>max) {
            return max(A, start + 1, A[i]);
      return max(A, start + 1, max);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.