File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-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 Rockpapergame {
5+ public static void main (String [] args ) {
6+
7+ Scanner sc = new Scanner (System .in );
8+ Random rc = new Random ();
9+
10+ System .out .println ("enter 0 for rock, 1 for Paper and 2 for scissor" );
11+ int user = sc .nextInt ();
12+
13+ int computer = rc .nextInt (3 );
14+
15+ if (user == computer ) {
16+ System .out .println ("draw" );
17+ } else if ( user ==0 && computer ==1 || user ==1 && computer ==2 || user ==2 && computer ==0 ){
18+ System .out .println ("you lost" );
19+ } else {
20+ System .out .println ("you win " );
21+ }
22+ System .out .println ("computer chose : " +computer );
23+ if (computer ==0 ){
24+ System .out .println ("computer chose rock" );
25+ }else if (computer ==1 ) {
26+ System .out .println ("computer chose paper" );
27+
28+
29+ }else {
30+ System .out .println ("computer chose rock" );
31+ }
32+
33+
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments