-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rock_Paper_Scissor.java
69 lines (61 loc) · 2.19 KB
/
Rock_Paper_Scissor.java
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
60
61
62
63
64
65
66
67
68
69
import java.util.Scanner;
import java.util.Random;
class Rock_Paper_Scissor {
public static void main(String[] args) {
int n = 0, c = 0, u = 0;
Scanner sc = new Scanner(System.in);
Random r = new Random();
System.out.println("**** RULE FOR THIS GAME ****");
System.out.println("1.Rock\n2.Paper\n3.Scissor\n4.Exit\n");
while (true) {
System.out.print("User:- ");
int input = sc.nextInt();
if (input == 4) {
break;
}
int random = 0;
while (true) {
random = r.nextInt(4);
if (random != 0) {
break;
}
}
System.out.println("Computer :- " + random);
switch (input) {
case 1:
if (random == 1) {
System.out.println("Tie!\n");
break;
} else if (random == 2) {
System.out.println("Computer Win!\n");
break;
} else if (random == 3) {
System.out.println("You Win!\n");
break;
}
case 2:
if (random == 1) {
System.out.println("You Win!\n");
break;
} else if (random == 2) {
System.out.println("Tie!\n");
break;
} else if (random == 3) {
System.out.println("Computer Win!\n");
break;
}
case 3:
if (random == 1) {
System.out.println("Computer Win!\n");
break;
} else if (random == 2) {
System.out.println("You Win!\n");
break;
} else if (random == 3) {
System.out.println("Tie!\n");
break;
}
}
}
}
}