-
Notifications
You must be signed in to change notification settings - Fork 106
/
StonePaperScissor.java
173 lines (87 loc) Β· 2.87 KB
/
StonePaperScissor.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import java.util.Random;
import java.util.Scanner;
public class StonePaperScissor
{
public static void main(String [] args)
{
Scanner input=new Scanner(System.in);
Random obj=new Random();
System.out.println("Welcome to the Game!!\nLet's go to the Hint.");
System.out.println("Enter 1 for Stone\nEnter 2 for Paper\nEnter 3 for Scissor");
System.out.println("Enter no. of times you want to play= ");
int a=input.nextInt();
int min=1;
int max=3;
int s1=0,s2=0,s3=0;
String c1="",c2="",c3="";
for(int i=1;i<=a;i++)
{
System.out.println("Enter your choice= ");
int b=input.nextInt();
int c=obj.nextInt(max-min)+min;
if(b==1)
{
System.out.println("You chose Stone");
if(c==1)
c1="Stone";
else if(c==2)
c1="Paper";
else
c1="Scissor";
System.out.println("Computer Chose= "+c1);
}
else if(b==2)
{
System.out.println("You chose Paper");
if(c==1)
c2="Stone";
else if(c==2)
c2="Paper";
else
c2="Scissor";
System.out.println("Computer Chose= "+c2);
}
else if(b==3)
{
System.out.println("You chose Scissor");
if(c==1)
c3="Stone";
else if(c==2)
c3="Paper";
else
c3="Scissor";
System.out.println("Computer Chose= "+c3);
}
if(c==1 && b==1 || c==2 && b==2 || c==3 && b==3)
{
System.out.println("Match Drawn.");
s3++;
System.out.println("Your Score= "+s1+" , "+ " Computer Score= "+s2+" , "+" Drawn= "+s3);
}
else if(b==1 && c==3 || b==2 && c==1 || b==3 && c==2)
{
System.out.println("You Won!!");
s1++;
System.out.println("Your Score= "+s1+" , "+ " Computer Score= "+s2+" , "+" Drawn= "+s3);
}
else if(b>3)
{
System.out.println("Invalid Choice...");
}
else
{
System.out.println("Computer Won!!");
s2++;
System.out.println("Your Score= "+s1+" , "+ " Computer Score= "+s2+" , "+" Drawn= "+s3);
}
}
if(s1>s2)
{
System.out.println("\nHurrahh!! You Won The Game.");
}
else
{
System.out.println("\nSorry!! You Lost the Game\nBetter Luck next time!!");
}
}
}