Skip to content

Commit 39b7e5c

Browse files
committed
多维数组
1 parent 074f83d commit 39b7e5c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Part3/LotteryArray.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
public class LotteryArray {
2+
public static void main(String[] args) {
3+
final int NMAX = 10;
4+
5+
int[][] odds = new int[NMAX + 1][];
6+
for (int n = 0; n <= NMAX; n++) {
7+
odds[n] = new int[n + 1];
8+
}
9+
10+
for (int n = 0; n < odds.length; n++) {
11+
for (int k = 0; k < odds[n].length; k++) {
12+
int lotteryOdds = 1;
13+
for (int i = 1; i <= k; i++) {
14+
lotteryOdds = lotteryOdds * (n - i + 1) / i;
15+
}
16+
odds[n][k] = lotteryOdds;
17+
}
18+
}
19+
20+
for (int[] row : odds) {
21+
for (int odd : row) {
22+
System.out.printf("%4d", odd);
23+
}
24+
System.out.println();
25+
}
26+
}
27+
}
28+

0 commit comments

Comments
 (0)