-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockPaperScissor.java
More file actions
60 lines (50 loc) · 1.49 KB
/
RockPaperScissor.java
File metadata and controls
60 lines (50 loc) · 1.49 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
import java.util.Scanner;
import java.util.Random;
public class RockPaperScissor {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
int i = 0;
while(i==0) {
String choice;
String hand[] = {"rock","paper","scissor"};
Random rand = new Random();
choice = hand[rand.nextInt(hand.length)];
System.out.println("rock, paper, scissor or quit? ");
String uchoice = scanner.nextLine();
if(uchoice.equals(choice)) {
System.out.println(choice);
System.out.println("Draw");
}
else if(uchoice.equals("paper") && choice.equals("rock")) {
System.out.println(choice);
System.out.println("You Win");
}
else if(uchoice.equals("rock") && choice.equals("paper")) {
System.out.println(choice);
System.out.println("Loser!");
}
else if(uchoice.equals("paper") && choice.equals("scissor")) {
System.out.println(choice);
System.out.println("Loser!");
}
else if(uchoice.equals("scissor") && choice.equals("paper")) {
System.out.println(choice);
System.out.println("You Win");
}
else if(uchoice.equals("rock") && choice.equals("scissor")) {
System.out.println(choice);
System.out.println("You Win");
}
else if(uchoice.equals("scissor") && choice.equals("rock")) {
System.out.println(choice);
System.out.println("Loser");
}
else if(uchoice.equals("quit")) {
i++;
}
else {
System.out.println("Invalid input, choose between 'rock', 'paper', 'scissor' and 'quit' ");
}
}
}
}