-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockPaperScissor.java
More file actions
57 lines (57 loc) · 2.13 KB
/
RockPaperScissor.java
File metadata and controls
57 lines (57 loc) · 2.13 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
package com.company;
import java.util.*;
public class RockPaperScissor {
public static void main(String[] args) {
Random rand = new Random();
Scanner sc = new Scanner(System.in);
byte compScore = 0,humanScore = 0;
System.out.println("1-Rock\n2-Paper\n3-Scissor");
for (int i = 0; i < 3; i++) {
System.out.println("Enter your choice");
byte my_choice=sc.nextByte();
byte comp_choice=(byte)(rand.nextInt(3)+1);
if(comp_choice==my_choice) {
System.out.println("It is tie for this round");
}
else if(comp_choice==1 && my_choice==3) {
System.out.println("Computer's choice is Rock");
compScore++;
System.out.println("Computer wins");
}
else if (comp_choice==3 && my_choice==1){
System.out.println("Computer's choice is Scissor");
humanScore++;
System.out.println("Human wins");
}
else if(comp_choice==3 && my_choice==2){
System.out.println("Computer's choice is Scissor");
compScore++;
System.out.println("Computer wins");
}
else if(comp_choice==2 && my_choice==3){
System.out.println("Computer's choice is Paper");
humanScore++;
System.out.println("Human wins");
}
else if(comp_choice==2 && my_choice==1){
System.out.println("Computer's choice is Paper");
compScore++;
System.out.println("Computer wins");
}
else if(comp_choice==1 && my_choice==2){
System.out.println("Computer's choice is Rock");
humanScore++;
System.out.println("Human wins");
}
}
if(humanScore==compScore){
System.out.println("Tie");
}
else if(humanScore<compScore){
System.out.println("Computer is the winner");
}
else {
System.out.println("Human is the winner");
}
}
}