title: Simple Insertion Sort in Java
body: <p>I had written a simple insertion sort program but the output is not coming correctly.</p>
  
  <pre><code>class InsertionSort{
      public static void main(String h[]){
      int[] a = {5,4,3,2,1};
      int i,j,temp;
          for(i=1;i&lt;a.length;i++){
              j = i-1; 
              while(i&gt;0 &amp;&amp; a[j] &gt; a[i]){
                  temp = a[i];
                  a[i] = a[j];
                  a[j] = temp;
              }
          }
          for(int x=0; x&lt;a.length;x++){
              System.out.println(a[x]);   
          }
      }
  }
  </code></pre>