Skip to content

Commit a7f29b7

Browse files
committed
for循环
1 parent 378aac3 commit a7f29b7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Part3/LotteryOdds.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.util.*;
2+
3+
public class LotteryOdds {
4+
public static void main(String[] args) {
5+
Scanner in = new Scanner(System.in);
6+
7+
System.out.print("How many numbers do you need to draw? ");
8+
int k = in.nextInt();
9+
10+
System.out.print("What is the highest number you can draw? ");
11+
int n = in.nextInt();
12+
13+
int lotteryOdds = 1;
14+
for (int i = 1; i <= k; i++) {
15+
lotteryOdds = lotteryOdds * (n - i + i) / i;
16+
}
17+
18+
System.out.println("Your odds are 1 in " + lotteryOdds + ". Good luck!");
19+
}
20+
}
21+
22+

0 commit comments

Comments
 (0)