title: Array out of bound exception in calling method, How to return whole array from a method
body: <p>This program is basic insertion sort. I am getting <code>ArrayIndexOutOfBoundsException</code> at line numbers 22 and 44. Help me in solving this issue.How to return sorted whole array from insertion method. 
  return a[] is not working..............................................                            </p>
  
  <pre><code>package analysis;
  
  import java.util.*;
  
  class Sort
  {
      int i,j,n,temp;
      int a[] = new int[n];
  
      int insertion(int a[],int n)
      {
          for (i=1;i&lt;n;i++) {
              j=i-1;
              while (i&gt;0 &amp;&amp; a[j]&gt;a[i]) {
                  temp = a[j];
                  a[j] = a[i];
                  a[i] = temp;
                  i--;
                  j--;
              }
          }
          return a[n];
      }
  }
  
  class Recurse
  {
      private static Scanner sc;
  
      public static void main(String[] args)
      {
          System.out.println("enter array size");
          int l,s;
          sc = new Scanner(System.in);
          s = sc.nextInt();
          int b[] = new int[s];
          int c[] = new int[s];
          for (l=0;l&lt;s;l++) {
              b[l] = sc.nextInt();
          }
          Sort so = new Sort();
          c[s] = so.insertion(b,s);
          System.out.println("Sorted array is ");
          for (l=0;l&lt;s;l++) {
              System.out.println(c[l]);
          }
      }
  }
  </code></pre>