-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrps_game.java
More file actions
38 lines (32 loc) · 1.16 KB
/
rps_game.java
File metadata and controls
38 lines (32 loc) · 1.16 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
import java.util.Random;
import java.util.Scanner;
/*
rock = 0
paper = 1
scissor = 2
*/
public class rps_game {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("choose 0 for rock, 1 for paper and 2 for scissor : ");
int userChoice = sc.nextInt();
Random rand = new Random();
int computerChoice = rand.nextInt(2);
if (computerChoice == 0) {
System.out.println("computer choose : Rock");
} else if (computerChoice == 1) {
System.out.println("computer choose : paper");
} else if (computerChoice == 2) {
System.out.println("computer choose : scissor");
}
if (computerChoice == userChoice) {
System.out.println("Draw match");
} else if (computerChoice == 0 && userChoice == 2 || userChoice == 1 && computerChoice == 0
|| userChoice == 2 && computerChoice == 1) {
System.out.println("You win");
} else {
System.out.println("computer win");
}
sc.close();
}
}