Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 0ee90b3

Browse files
authored
Add files via upload
1 parent d3a9272 commit 0ee90b3

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

BlueBook/BlueBookTriangle.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
5+
public class BlueBookTriangle {
6+
7+
public static long factorial(long n) {
8+
if (n == 0) {
9+
return 1;
10+
} else {
11+
return n * factorial(n - 1);
12+
}
13+
}
14+
15+
public static long combination(long n, long r) {
16+
return factorial(n) / (factorial(r) * factorial(n - r));
17+
}
18+
19+
public static void main(String[] args) throws IOException {
20+
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
21+
22+
long n = Integer.parseInt(in.readLine());
23+
24+
for (long i = 0; i < n; i++) {
25+
for (long j = 0; j <= i; j++) {
26+
if (j < i) {
27+
System.out.print(combination(i, j) + " ");
28+
} else {
29+
System.out.println(combination(i, j));
30+
}
31+
}
32+
}
33+
34+
}
35+
36+
}

0 commit comments

Comments
 (0)