 <p>Just change your for loop,</p> <pre><code> for(int row=0; row&lt;1; row++){ for(int column = 0; column&lt;x[row].length; column++){ System.out.println(x[row][column] + "\t"+x[row+1][column] ); } System.out.print("\n"); } </code></pre> <p>into below this will work even you have 5000 rows, </p> <pre><code> for(int row=0; row&lt;x.length-1; row++){ for (int column = 0; column &lt; x.length; column++) { System.out.print(x[column][row] + "\t" ); } System.out.println(); } </code></pre>