Java and I need help understanding what code to write out

Once you get the input:

  1. if check the input is equal to “1”, then print “Rock”.

  2. else if check the input is equal to “2”, then print “Paper”.

  3. else if check the input is equal to “3”, then print “Scissors”.

  4. else, then print “invalid input”.

The pseudo code for the above steps is below:

if computer input is int, declare input as int and use input == 1, meaning compare input value with == for 1,2 and 3 instead of input.equals(“1”) or “2” and “3”.

or if you want to convert int to String, use this Integer.toString(int value); where this method converts int value to String.

if(input.equals("1"))
{
    System.out.println("Rock");
}
else if(input.equals("2"))
{
    //print paper
}
else if(input.equals("3"))
{
    //print Scissors
}
else
{
    //invalid input
}

Leave a Comment