File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .Random ;
2
+ import java .util .Scanner ;
3
+
4
+ public class cwh_41_ex2sol {
5
+ public static void main (String [] args ) {
6
+ // 0 for Rock
7
+ // 1 for Paper
8
+ // 2 for Scissor
9
+
10
+ Scanner sc = new Scanner (System .in );
11
+ System .out .print ("Enter 0 for Rock, 1 for Paper, 2 for Scissor " );
12
+ int userInput = sc .nextInt ();
13
+
14
+ Random random = new Random ();
15
+ int computerInput = random .nextInt (3 );
16
+
17
+ if (userInput == computerInput ) {
18
+ System .out .println ("Draw" );
19
+ }
20
+ else if (userInput == 0 && computerInput == 2 || userInput == 1 && computerInput == 0
21
+ || userInput == 2 && computerInput == 1 ) {
22
+ System .out .println ("You Win!" );
23
+ } else {
24
+ System .out .println ("Computer Win!" );
25
+ }
26
+ // System.out.println("Computer choice: " + computerInput);
27
+ if (computerInput ==0 ){
28
+ System .out .println ("Computer choice: Rock" );
29
+ }
30
+ else if (computerInput ==1 ){
31
+ System .out .println ("Computer choice: Paper" );
32
+ }
33
+ else if (computerInput ==2 ){
34
+ System .out .println ("Computer choice: Scissors" );
35
+ }
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments