title: Upper Triangular Matrix in Java
body: <p>I have a query which generates the following result set </p>
  
  <pre><code>rs = [51,88,93,89,91,26,51,47,47,31,67,68,46,92,39]
  </code></pre>
  
  <p>my matrix size is 5X5 and I want the final result as upper triangular matrix</p>
  
  <pre><code>51  88  93  89  91
  
  0   26  51  47  47
  
  0   0   31  67  68
  
  0   0   0   46  92
  
  0   0   0   0   39
  </code></pre>
  
  <p>My code : But does not generate the desired O/P</p>
  
  <pre><code>int rowCount = 5;
  String[][] result = new String[rowCount][];
  for (int i = 0; i &lt; rowCount; i++) {
      Cell[] row = sheet.getRow(i);
  
      result[i] = new String[row.length];
      for (int j = 0; j &lt; row.length; j++) {
          if(i&lt;=j){
              result[i][j] = row[j].getContents();
              System.out.print(result[i][j] + " ");
          }else{
              result[i][j] = "0";
              System.out.print(result[i][j] + " ");
          }
      }
      System.out.print("\n");
  }
  </code></pre>
  
  <p>Can you please help what to change in the code to get the proper matrix.</p>