title: print 2d array diagonally from bottom to top
body: <p>I have a two dimensional array in my java prgm </p>
  
  <pre><code>[ 1 2 3   
    4 5 6  
    7 8 9 ]
  </code></pre>
  
  <p>How to arrange this matrix diagonally in clockwise direction..such as</p>
  
  <pre><code>[ 9 8 6  
    7 5 3  
    4 2 1 ]
  </code></pre>
  
  <p>this should be applicable for all square matrix of order N.
  can anybody help me</p>
  
  <pre><code>class try2
     {
      public static void main (String[] args) throws java.lang.Exception
      {
  
  
   int[][] elements = new int[][]{
              {1,5,9,13},
              {2,6,10,14},
              {3,7,11,15},
              {4,8,12,16}
      };
  
  
      int i=0,j=0,k=0,l = 0;
      int rows = 4,columns = 4;
      // Elements to the left of secondary diagonal elements. 
      while(i&lt;rows){
  
          k = i;
          j=0;
         // System.out.print("1 loop");
           //System.out.println(" "+k+""+j);
          while(k&gt;=0 &amp;&amp; j&gt;=0 &amp;&amp; k&lt;rows &amp;&amp; j&lt;columns){
              System.out.print(elements[k][j]+" ");
              j++;
              k--;
          }
          i++;
          System.out.println();
      }
      i = rows-1;
      j = 1;
      // elements to the right of secondary diagonal elements. 
      while(j&lt;columns){
          k = i;
          l = j;
         //System.out.print("2 loop");
           //System.out.println(" "+k+""+l);
          while(l&lt;columns){
              System.out.print(elements[k][l]+" ");
              l++;
              k--;
          }
          System.out.println();
          j++;
      }
  }
  }
  </code></pre>
  
  <p>output is </p>
  
  <pre><code>1  
  2 5  
  3 6 9  
  4 7 10 13   
  8 11 14   
  12 15   
  16 
  </code></pre>
  
  <p>desired output is</p>
  
  <pre><code>16  
  12 15  
  8 11 14  
  4 7 10 13  
  3 6 9  
  2 5  
  1
  </code></pre>