Sha256: 282ebfa4abca331511c27e7f990cebcab858ec530e0ea00fc81c82babe534890

Contents?: true

Size: 483 Bytes

Versions: 245

Compression:

Stored size: 483 Bytes

Contents

class PascalsTriangleGenerator {

  int[][] generateTriangle(int rows) {
    if (rows < 0) {
      throw new IllegalArgumentException("Rows can't be negative!");
    }

    int[][] triangle = new int[rows][];

    for (int i = 0; i < rows; i++) {
      triangle[i] = new int[i + 1];
      triangle[i][0] = 1;
      for (int j = 1; j < i; j++) {
        triangle[i][j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
      }
      triangle[i][i] = 1;
    }
    return triangle;
  }

}

Version data entries

245 entries across 245 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.138 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.137 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.136 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.135 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.134 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.133 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.132 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.131 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.130 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.129 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.128 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.127 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.126 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.125 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.124 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.123 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.122 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.121 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.120 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java