-
Notifications
You must be signed in to change notification settings - Fork 0
/
RockPaperScissor.java
54 lines (49 loc) · 1.62 KB
/
RockPaperScissor.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Scanner;
public class RockPaperScissor{
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
// rock='r',paper='p',scissor='s';
int countx=0,county=0;
System.out.println("Enter number of rounds: ");
int t= sc.nextInt();
System.out.println("Enter 1 for rock,2 for paper and 3 for scissor :");
while(t!=0){
System.out.println("Entry for player 1: ");
int x= sc.nextInt();
System.out.println("Entry for player 2: ");
int y= sc.nextInt();
if(x==1 && y==2){
System.out.println("Player 1 wins!");
countx++;
}
else if(x==2 && y==1){
System.out.println("Player 2 wins!");
county++;
}
if(x==2 && y==3){
System.out.println("Player 2 wins!");
county++;
}
else if(x==3 && y==2){
System.out.println("Player 1 wins!");
countx++;
}
if(x==1 && y==3){
System.out.println("Player 1 wins!");
countx++;
}
else if(x==3 && y==1){
System.out.println("Player 2 wins!");
county++;
}
t--;
}
if(countx>county)
System.out.println("Player 1 wins with "+countx+" points");
else if(countx<county)
System.out.println("Player 2 wins with "+county+" points");
else
System.out.println("It is a Tie");
sc.close();
}
}