-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrockPaperGame.java
101 lines (88 loc) · 3.22 KB
/
rockPaperGame.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Create a rock paper scissor game.
import java.util.Scanner;
import java.util.Random;
public class rockPaperGame {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Random ran = new Random();
System.out.println("Welcome to Game");
System.out.println("R for Rock");
System.out.println("P for Paper");
System.out.println("S for Scissor");
int i = 0;
int tie = 0;
int user = 0;
int com = 0;
while(i<5) {
String choice = sc.next();
int c = ran.nextInt(3);
switch (choice) {
case "R" -> {
if (c == 0) {
String Pr = "Rock";
System.out.println("Rock : " + Pr);
System.out.println("Its a tie");
tie++;
} else if (c == 1) {
String Pr = "Paper";
System.out.println("Rock : " + Pr);
System.out.println("Computer wins");
com++;
} else {
String Pr = "Scissor";
System.out.println("Rock : " + Pr);
System.out.println("You win");
user++;
}
}
case "P" -> {
if (c == 0) {
String Pr = "Rock";
System.out.println("Paper : " + Pr);
System.out.println("You wins");
user++;
} else if (c == 1) {
String Pr = "Paper";
System.out.println("Paper : " + Pr);
System.out.println("Its a tie");
tie++;
} else {
String Pr = "Scissor";
System.out.println("Paper : " + Pr);
System.out.println("Computer win");
com++;
}
}
case "S" -> {
if (c == 0) {
String Pr = "Rock";
System.out.println("Scissor : " + Pr);
System.out.println("Computer wins");
com++;
} else if (c == 1) {
String Pr = "Paper";
System.out.println("Scissor : " + Pr);
System.out.println("You win");
user++;
} else {
String Pr = "Scissor";
System.out.println("Scissor : " + Pr);
System.out.println("Its a tie");
tie++;
}
}
}
i++;
System.out.println("You :"+ user +" |Computer :"+ com +"|Tie :"+tie);
}
if(user==com){
System.out.println("Overall Its a tie");
}
else if(user>com){
System.out.println("Overall You win");
}
else{
System.out.println("Computer Wins");
}
}
}