Rock, paper, scissors

java

#1

Hi, i was just doing some practice on my own.
can someone please point out what i’m doing wrong?

import java.util.Scanner;
public class RockPaperScissor {
public static void main(String[] args){
Scanner input = new Scanner(System.in);

    System.out.println("Enter a number: , 0 for scissor, 1 for rock ,"
            + " 2 for paper");
    int number = input.nextInt();


    
  
    int computer = 0 + (int)(Math.random() * ((3 - 0) + 1));

    if (number == computer) 
            System.out.println("It is a draw!");
    else  if (number == 0)
        if (computer == 2)
            System.out.println("You're scissors. You win!");
        else if (number == 1)
            System.out.println("You're scissor. You lose!");
    else if (number == 1)
        if (computer == 2)
            System.out.println("You're rock. You lose!");
        else if (computer == 0)
            System.out.println("You're rock. You win!");
    else if (number == 2)
        if (computer == 1)
            System.out.println("You're paper. You win!");
        else if (computer == 0)
            System.out.println("You're scissors. You lose!");
        else
            System.out.println("Invalid user input.");

#2

The logic error that keeps it from working properly is that there is a ‘number’ where there should be a ‘computer’ in one of else-if statements.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.