title: Getting the largest element in an array using recursion
body: <p>I have an assignment to use recursion to obtain the largest element in any given array.  I have the following code which will work unless the largest element is the last in the array.  </p>
  
  <p>Not sure how to correct this?</p>
  
  <pre><code>import java.util.Scanner;
  public class RecursionLargestInArray
  {
  public static void main (String[] args)
  {
      int max = -999;
      Scanner scan = new Scanner (System.in);
      System.out.print("Enter the size of the array: ");
      int arraySize = scan.nextInt();
      int[] myArray = new int[arraySize];
      System.out.print("Enter the " + arraySize + " values of the array: ");
      for (int i = 0; i &lt; myArray.length; i++)
          myArray[i] = scan.nextInt();
      for (int i = 0; i &lt; myArray.length; i++)
          System.out.println(myArray[i]);
      System.out.println("In the array entered, the larget value is "
                          + getLargest(myArray, max) + ".");
  }
  
  public static int getLargest(int[] myArray, int max)
  {    
      int i = 0, j = 0, tempmax = 0;
      if (myArray.length == 1)
      {
          return max;
      }
      else if (max &lt; myArray[i])
      {
          max = myArray[i];
          int[] tempArray = new int[myArray.length-1];
          for (i = 1; i &lt; myArray.length; i++)
          {
              tempArray[j] = myArray[i];
              j++;
          }
          tempmax = getLargest(tempArray, max);
          return tempmax;
      }
      else if
      {
          int[] tempArray = new int[myArray.length-1];
          for (i = 1; i &lt; myArray.length; i++)
          {
              tempArray[j] = myArray[i];
              j++;
          }
          tempmax = getLargest(tempArray, max);
          return tempmax;
      }
  }
  }
  </code></pre>