java - Pascal's Triangle Format -
the assignment create pascal's triangle without using arrays. have method produces values triangle below. method accepts integer maximum number of rows user wants printed.
public static void triangle(int maxrows) { int r, num; (int = 0; <= maxrows; i++) { num = 1; r = + 1; (int col = 0; col <= i; col++) { if (col > 0) { num = num * (r - col) / col; } system.out.print(num + " "); } system.out.println(); } }
i need format values of triangle such looks triangle:
i can't life of me figure out how that. please answer keeping in mind i'm beginner in java programming.
thank you!
public static long pascaltriangle(int r, int k) { if(r == 1 || k <= 1 || k >= r) return 1l; return pascaltriangle(r-1, k-1) + pascaltriangle(r-1, k); }
this method allows find kth value of rth row.
Comments
Post a Comment