-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRPScomputer.java
More file actions
28 lines (23 loc) · 856 Bytes
/
RPScomputer.java
File metadata and controls
28 lines (23 loc) · 856 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
import java.util.Random;
import java.util.Scanner;
public class RPScomputer{
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
System.out.println("Enter number of rounds: ");
int t= sc.nextInt();
System.out.println("Enter 0 for rock,1 for paper and 2 for scissor :");
while(t!=0){
int user = sc.nextInt();
Random random= new Random();
int computer= random.nextInt(3);
if(user==computer)
System.out.println("Draw");
else if((user==1 && computer==0)|| (user==2 && computer==1) || (user==0 && computer==2))
System.out.println("You win!");
else
System.out.println("Computer wins!");
t--;
}
sc.close();
}
}