-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockPaper.java
More file actions
65 lines (55 loc) · 1.68 KB
/
RockPaper.java
File metadata and controls
65 lines (55 loc) · 1.68 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
import java.util.Scanner; // #include <iostream>
import java.util.Random;
public class RockPaper {
public static void main (String[] args)
{
// MENU
System.out.print(" MENU \n");
System.out.println(" 1. Rock \n 2. Paper \n 3. Scissors");
// Input
Scanner obj = new Scanner(System.in);
Random ran = new Random(); // code with harry for computer logic
/*
General Rules before applying logic
Same means draw!
Rock beats Scissors
Paper beats Rock
Scissors beats Paper
there are total 6 possibilities excluding draw
3 possibilities win for user
3 possibilities for computer
*/
// User Input
int user, computer; // first define always bro
do // see same as c++
{
System.out.print(" Enter a number : ");
user = obj.nextInt();
} while(user < 1 || user > 3);
// computer input
do // see same as c++
{
computer = ran.nextInt(4); // 0 to 3
} while(computer < 1);
System.out.println(" Computer picked option : " + computer);
if (user == computer) // draw possibilities are of 3
{
System.out.println(" TIE! ");
}
else if(user == 1 && computer == 3)
{
System.out.println(" USER WINS! ");
}
else if(user == 2 && computer == 1)
{
System.out.println(" USER WINS! ");
}
else if(user == 3 && computer == 2)
{
System.out.println(" USER WINS! ");
}
else {
System.out.println(" COMPUTER WINS! ");
}
}
}