-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path29_LuckyDraw.java
More file actions
59 lines (46 loc) · 1.57 KB
/
29_LuckyDraw.java
File metadata and controls
59 lines (46 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// WAP to create a lucky draw where user draws between 1 and 20 out of which only one is winner.
import java.util.*;
class Solution {
static int winner, counter;
static boolean draw(){
Scanner sc = new Scanner(System.in);
System.out.print("Enter Num to Draw between (1 <= n <= 20): ");
int num = sc.nextInt();
if (num == winner) return true;
return false;
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
boolean game = true;
while(game){
winner = ((int)(Math.random()+1))%20 + 1;
System.out.println("-- Lucky Draw --\n");
System.out.println("Choose Option:");
System.out.println("1: Draw");
System.out.println("2: Exit");
int choice;
System.out.print("Enter Choice: ");
choice = sc.nextInt();
if (choice == 1) {
counter++;
if (draw()){
System.out.println("Congratulations! You won the draw in " + counter);
break;
}
else {
System.out.println("Better Luck Next Time\n");
}
}
else if (choice == 2) {
game = false;
}
else {
System.out.println("Enter valid Choice");
}
}
if (game == false) {
System.out.println("\nLucky number was: " + winner);
}
System.out.println("Bye");
}
}