-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockPapperSeissors.java
More file actions
94 lines (71 loc) · 1.53 KB
/
RockPapperSeissors.java
File metadata and controls
94 lines (71 loc) · 1.53 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
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
import java.util.Random;
import java .util.Scanner;
public class RockPapperSeissors {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int a = 0;
int user=0;
int computer = 0;
int i = 0;
boolean check= false;
boolean winner= false;
while(i<5) {
System.out.println("enter - rock,papper,scissor");
String str = sc.nextLine();
switch (str) {
case "rock" : a = 0;
i++;
break;
case"papper": a= 1;
i++;
break;
case"scissor": a =2;
i++;
break;
default:
System.out.println("wrong input");
check = true;
winner=false;
break;
}
if(check==true)
break;
//0>2>1>0
Random r = new Random();
int random = r.nextInt(3);
switch(random)
{ case 0 : System.out.println("rock");
break;
case 1: System.out.println("papper");
break;
case 2: System.out.println("scissor");
break;
}
if(a==random)
System.out.println("draw");
else if(a==0 && random==2)
{System.out.println("You won");
user++;}
else if(a==0 && random==1)
{System.out.println("Computer won");
computer++;}
else if(a==1 && random==2)
{System.out.println("Computer won");
computer++;}
else if(a==1 && random==0)
{System.out.println("You won");
user++;}
else if (a==2 && random==1)
{System.out.println("You won");
user++;}
else if(a==2 && random == 0)
{System.out.println("Computer won");
computer++;}
}
if(user>computer&& winner==true)
System.out.println("user won by "+(user-computer)+" points");
else if(user<computer&& winner==true)
System.out.println("computer won by "+(computer-user)+" pints");
}
}