title: Finding the middle element of an array
body: <p>Java newbie here.
  I have the following code from which I would want it to return the middle elements of the array. How do I go about that? I don't want to just manually return the elements at position 5 and 6, which are the median elements here. I would it in a way that would work for any array type, even or odd.</p>
  
  <pre><code>      /**
   * Created by root on 2/11/15.
   */
  import java.util.Scanner;
  import java.util.Arrays;
  
  public class  test {
  
  
  
      public static void main(String[] args){
  
         Scanner scan = new Scanner(System.in);
          //Create a string array to store the names
   String arrayOfNames[] = new String[10];
   System.out.print("Enter 10 names\n");
          for (int i = 0; i &lt; arrayOfNames.length; i++) {
  
              System.out.print("\n" + (i+1) + " : ");
  
              arrayOfNames[i] = scan.nextLine();
  
          }
  
          //show  name one by one
       Arrays.sort(arrayOfNames);
       System.out.print("Names ");
  
          for (int i = 0; i &lt; arrayOfNames.length; i++) {
  
              System.out.print("" + (i+1) + " : ");
  
              System.out.print(arrayOfNames[i] + "\n");
  
  
  
          }
  
  
      }
  
  }
  </code></pre>