forked from Raju1822/HacktoberFest_2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stone Paper Scissor.
91 lines (87 loc) · 2.79 KB
/
Stone Paper Scissor.
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
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!!");
}
}
}