-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRPSGAME.java
More file actions
98 lines (70 loc) · 3.21 KB
/
Copy pathRPSGAME.java
File metadata and controls
98 lines (70 loc) · 3.21 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.util.Random;
import java.util.Scanner;
public class RPSGAME {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("What is your name ?");
String name = sc.nextLine();
System.out.println("\n");
System.out.printf("Hello %s\n",name);
System.out.println("\n");
System.out.println("1 : rock\n 2 : paper\n 3 :scissor\n");
int player = 0;
int compiler = 0;
int draw = 0;
for(int i=1; i<=5; i++){
System.out.println("your chance input number (1-3)");
int number = sc.nextInt();
int max = 3,min =1;
Random ran = new Random();
int Randomnumber = ran.nextInt(max - min + 1 )+ min;
System.out.println("compiler chance");
System.out.println(Randomnumber);
if((number==1 && Randomnumber==1 ) || (number==2 && Randomnumber==2 ) || (number == 3 && Randomnumber==3)){
System.out.println("Match Draw");
draw = draw +1;
}
else if(number==1 && Randomnumber==3){
System.out.printf("%s is winner\n",name);
player = player +1;
}
else if(number==3 && Randomnumber==1) {
System.out.println("compiler is winner");
compiler = compiler+1;
}
else if(number==2 && Randomnumber==1){
System.out.printf("%s is winner\n",name);
player = player +1;
}
else if(number==1 && Randomnumber==2){
System.out.println("compiler is winner");
compiler = compiler+1;
}
else if(number==3 && Randomnumber==2){
System.out.printf("%s is winner\n",name);
player = player +1;
}
else if(number==2 && Randomnumber==3){
System.out.println("compiler is winner");
compiler = compiler+1;
}
else{
System.out.println("Invalid input");
}
}
System.out.println("\n");
System.out.println("draw is " + draw + " time");
System.out.printf( "%s winner is %d time\n",name,player);
System.out.println("compiler is winner in " + compiler + " time");
System.out.println("\n");
if(player>compiler) {
System.out.printf("%s is winner",name);
}
else if(compiler > player) {
System.out.println("Compiler is winner");
}
else{
System.out.println("Match is DRAW");
}
}
}