Sha256: 16747d87bcc3c56034999aae123c8b9448ba5894ed01e9c0b7341d3b4a4e18eb

Contents?: true

Size: 733 Bytes

Versions: 151

Compression:

Stored size: 733 Bytes

Contents

import java.util.Arrays;

public class PascalsTriangle {

    public static int[][] computeTriangle(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;
    }

    public static boolean isTriangle(int[][] triangle) {
        return Arrays.deepEquals(triangle, computeTriangle(triangle.length));
    }
}

Version data entries

151 entries across 151 versions & 1 rubygems

Version Path
trackler-2.0.8.51 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.50 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.49 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.48 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.47 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.46 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.45 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.44 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.43 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.42 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.41 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.40 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.39 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.38 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.37 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.36 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.35 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.34 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.33 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java
trackler-2.0.8.32 tracks/java/exercises/pascals-triangle/src/example/java/PascalsTriangle.java