forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRockpaperScissorgame.java
35 lines (26 loc) · 966 Bytes
/
RockpaperScissorgame.java
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
import java.util.Random;
import java.util.Scanner;
public class Rockpapergame {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
Random rc = new Random();
System.out.println("enter 0 for rock, 1 for Paper and 2 for scissor");
int user = sc.nextInt();
int computer = rc.nextInt(3);
if (user == computer ) {
System.out.println("draw");
} else if ( user==0 && computer==1 || user ==1 && computer==2 || user==2 && computer==0){
System.out.println("you lost");
} else {
System.out.println("you win ");
}
System.out.println("computer chose : " +computer);
if (computer==0){
System.out.println("computer chose rock");
}else if (computer==1 ) {
System.out.println("computer chose paper");
}else {
System.out.println("computer chose rock");
}
}
}