Skip to content

Commit

Permalink
cleaned code, renamed file, fix: array wasn't fill fully
Browse files Browse the repository at this point in the history
  • Loading branch information
My- committed Jan 24, 2018
1 parent 6036e72 commit a622a6c
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package my.math;

public class PaskalTriangles {
public class PascalTriangles {
/**
* method outputs Pascal triange of given value
*/
public static int[][] pascalTriangle(final int n){
int[][] p = new int[n][];
// p[1] = new int[]{1};
// p[0] = new int[1];
// p[0][0] = 1;

for(int y = 0; y < p.length; y++){
// int middle = y / 2 +(y %2 == 0 ? 1 : 0);
p[y] = new int[y +1];
p[y][0] = 1;

for(int x = 1; x < p[y].length-1; x++){
int value = p[y -1][x -1] +p[y -1][x];
for(int x = 1; x < p[y].length; x++){
int value = p[y -1][x -1] +(x < p[y].length -1 ? p[y -1][x] : 0);
p[y][x] = value;
}
}
Expand All @@ -32,7 +28,6 @@ public static void printPascalTriangle(int[][] arr){
System.out.print(String.format("%"+ offset +"s", " "));

for(int i = 0; i < arr[row].length; i++ ){
// if( arr[row][i] == 0 ){ break; }
System.out.print(String.format("%6d", arr[row][i]));
}
System.out.println();
Expand Down

0 comments on commit a622a6c

Please sign in to comment.