Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Pascals-triangle/Java/pascals-triangle-2.java
Normal file
27
Task/Pascals-triangle/Java/pascals-triangle-2.java
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
public class Pas{
|
||||
public static void main(String[] args){
|
||||
//usage
|
||||
pas(20);
|
||||
}
|
||||
|
||||
public static void pas(int rows){
|
||||
for(int i = 0; i < rows; i++){
|
||||
for(int j = 0; j <= i; j++){
|
||||
System.out.print(ncr(i, j) + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
public static long ncr(int n, int r){
|
||||
return fact(n) / (fact(r) * fact(n - r));
|
||||
}
|
||||
|
||||
public static long fact(int n){
|
||||
long ans = 1;
|
||||
for(int i = 2; i <= n; i++){
|
||||
ans *= i;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue