Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7748827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:53:00+00:00 2026-06-01T10:53:00+00:00

Hopefully this is a quick question. I’m making a simple rock paper scissors game.

  • 0

Hopefully this is a quick question. I’m making a simple rock paper scissors game. I make a random computer choice fine, and get the user’s choice fine. But when I try to find who wins, it prints the last else in my else if block that is for invalid input.

It prints “Enter a valid choice” when a correct choice has been made.

import java.util.Random;
import javax.swing.JOptionPane;

public class JavaApplication4 {

    public static void main(String[] args) 
    {
        Random ranNums = new Random();

        int comp = ranNums.nextInt(3);
        String comp2;
        String winner;

        String user = JOptionPane.showInputDialog
                (null, "Enter rock, paper, or scissors");
        user.toLowerCase();

        if(comp == 0)
            comp2 = "rock";
        else if(comp == 1)
            comp2 = "paper";
        else 
            comp2 = "scissors";

        //Computer wins
        if(comp2 == "rock" && user == "scissors")
            winner = "The computer wins";

        else if(comp2 == "paper" && user == "rock")
            winner = "The computer wins";    

        else if(comp2 == "scissors" && user == "paper")
            winner = "The computer wins";

        //Tie game
        else if(comp2 == "rock" && user == "rock")
            winner = "It's a tie";

        else if(comp2 == "paper" && user == "paper")
            winner = "It's a tie";

        else if(comp2 == "scissors" && user == "scissors")
            winner = "It's a tie";

        //User wins
        else if(comp2 == "scissors" && user == "rock")
            winner = "You win!";

        else if(comp2 == "rock" && user == "paper")
            winner = "You win!";

        else if(comp2 == "paper" && user == "scissors")
            winner = "You win!";
        else
            winner = "Enter a valid choice";

        JOptionPane.showMessageDialog(null, "You picked " + user + "\n" +
            "The computer picked " + comp2 + "\n" +
                winner);



    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:53:02+00:00Added an answer on June 1, 2026 at 10:53 am

    you can’t use

    comp == "paper" 
    

    to compare strings in java. You use

    comp.equals("paper")
    

    or if case doesn’t matter

    comp.equalsIgnoreCase("paper")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully this question has a simple answer i'm overlooking! I have an IIS webserver
Hopefully this is a quick and easy question to answer. Do I need the
Hopefully this should be a quick question. I'm having trouble accessing some movie clips
I have a quick and hopefully simple question that I hope someone can help
Hopefully this question is quick and painless I have a mvc view where i
Hopefully a quick question, how can I get this to be well formed, and
I have a (hopefully) quick question. I've got some stepper boxes. Though really this
Hopefully a quick question. I'm trying to validate a double. Making sure it's positive
I have a quick (hopefully simple) question. I have some information stored in a
Hopefully this is a quick and easy question to answer. I have a MySQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.