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.180 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.179 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.178 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.177 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.176 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.175 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.174 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.173 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.172 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.171 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.170 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.169 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.167 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.166 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.165 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.164 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.163 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.162 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.161 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java
trackler-2.2.1.160 tracks/java/exercises/pascals-triangle/.meta/src/reference/java/PascalsTriangleGenerator.java