-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameRock.java
More file actions
42 lines (29 loc) · 963 Bytes
/
GameRock.java
File metadata and controls
42 lines (29 loc) · 963 Bytes
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
import java.util.Scanner;
public class GameRock{
public static void main(String[] args){
int number = (int)(Math.random()* 3);
Scanner input = new Scanner(System.in);
int game = 0;
while(game < 3){
System.out.print("Enter your choice (0 = Rock, 1 = Paper, 2 = Scissors, 9 = Quit): ");
game = input.nextInt();
if(game == 5){
System.out.println("Game Over");
break;
}
else if(game < 0 || game > 2){
System.out.println("Please enter a valid number.");
}
System.out.printf("Computer chose: %d%n",number );
if(game == number){
System.out.println("It is a draw");
}
else if((game == 0 && number == 2) || (game == 1 && number == 0) || (game == 2 && number == 1)){
System.out.println("You win!");
}
else {
System.out.println("Computer wins!");
}
}
}
}