-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRPS2.java
More file actions
45 lines (34 loc) · 1.29 KB
/
Copy pathRPS2.java
File metadata and controls
45 lines (34 loc) · 1.29 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
package Java;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class RPS2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
ArrayList<String> choices = new ArrayList<>(Arrays.asList("rock", "paper", "scissors"));
String comChoice = choices.get(random.nextInt(3));
String userChoice;
System.out.println("Rock, Paper, and Scissors");
while (true) {
System.out.print("User: ");
userChoice = scanner.nextLine().toLowerCase();
if (!choices.contains(userChoice)) {
continue;
}
scanner.close();
System.out.println("Com: " + comChoice);
if (userChoice.equals(comChoice)) {
System.out.println("Draw!");
} else if ((userChoice.equals("rock") && comChoice.equals("scissors"))
|| (userChoice.equals("paper") && comChoice.equals("rock"))
|| (userChoice.equals("scissors") && comChoice.equals("paper"))) {
System.out.println("You won!");
} else {
System.out.println("You loss!");
}
break;
}
}
}