There was an error while loading. Please reload this page.
1 parent 378aac3 commit a7f29b7Copy full SHA for a7f29b7
Part3/LotteryOdds.java
@@ -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