java - How to print a line based on user input and randomly selected choices -


i'm working on code first ever java class. rock paper scissors (lizard spock). program runs allowing input , outputting random choice computer. however, i'd program "its @ tie" or "you win" when situation right. far, haven't been able this. had "its tie" wrong situation once, , once without being able replicate it. code is:

import java.util.*;

class rock { public static void main( string args[ ] ) {

    system.out.println( "rock, paper, scissors, lizard, or spock?" );     scanner user_input = new scanner ( system.in );     string guess;     guess = user_input.next( );      string [ ] comp;         comp = new string [ 5 ];         comp[ 0 ] = "rock";         comp[ 1 ] = "paper";         comp[ 2 ] = "scissors";         comp[ 3 ] = "lizard";         comp[ 4 ] = "spock";          random hi;         hi = new random( );         system.out.println( "::" + guess +             ":: vs ::" + comp[ hi.nextint( 5 ) ] + "::") ;              if (guess.equals( "rock" ) & comp[ hi.nextint( 5 ) ].equals(1) ) system.out.println( "its tie" );  } 

}

i have 1 output right now, once understand add 1 each situation.

any appreciated! thanks!

multiple details might there:

you need use && instead of & test logical and

the convention class name starts caps: rock

you calling nextint() twice, potentially return 2 different values. if want same, should call once , store in variable.


Popular posts from this blog

html/hta mutiple file in audio player -

debugging - Reference - What does this error mean in PHP? -