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:

enter image description here

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

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -