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 8824597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:40:24+00:00 2026-06-14T06:40:24+00:00

Ok, so I have programmed a simple rock paper scissors game using user input

  • 0

Ok, so I have programmed a simple rock paper scissors game using user input to play. The user types their choice, a random function chooses the computers go and then a result is produced. After this the program is terminated because it has finished. I want to use a while loop so that when the game is finished, it starts again, and then the program will stop if the user types in exit or quit, which can easily be done by just saying something like while playerGo != exit, play the game blah blah. However, I cannot get this to work, can someone help me please, I’m a Java noob 🙂

import java.util.Scanner;   

public class RockPaperScissors{   
  public static void main(String[] args){  

    Scanner input = new Scanner(System.in);

    int compGoInt;
    String compGo;
    String playerGo;

    System.out.println("You can type 'Exit' to quit the game at any time.");
    System.out.print("Please enter your choice. Rock, Paper or Scissors: ");
    playerGo = input.nextLine();

    compGoInt = (int) (Math.random() * 3);

    switch (compGoInt){
    case 0:
        compGo = "Rock";
        break;
    case 1:
        compGo = "Paper";
        break;
    case 2:
        compGo = "Scissors";
        break;
    default:
        compGo = "Error";
        System.out.println("Error.");
        break;
    }

    if (playerGo.equals(compGo)){
        System.out.println("Computer chooses "+compGo);
        System.out.println("It's a draw!");
    }

    else if ((playerGo.equalsIgnoreCase("Rock") && compGo.equalsIgnoreCase("Scissors")) ||
            (playerGo.equalsIgnoreCase("Paper") && compGo.equalsIgnoreCase("Rock")) ||
            (playerGo.equalsIgnoreCase("Scissors") && compGo.equalsIgnoreCase("Paper"))){
        System.out.println("Computer chooses "+compGo);
        System.out.println("Player Wins!");
    }

    else if ((compGo.equalsIgnoreCase("Rock") && playerGo.equalsIgnoreCase("Scissors")) ||
            (compGo.equalsIgnoreCase("Paper") && playerGo.equalsIgnoreCase("Rock")) ||
            (compGo.equalsIgnoreCase("Scissors") && playerGo.equalsIgnoreCase("Paper"))){
        System.out.println("Computer chooses "+compGo);
        System.out.println("Computer Wins!");
    }

    else{
        System.out.println("Something has gone wrong!");
        System.out.println("Player chose "+playerGo);
        System.out.println("Computer chose "+compGo);
    }


}

}

  • 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-14T06:40:26+00:00Added an answer on June 14, 2026 at 6:40 am

    Simply put:

    while(true) {
         if(playerGo.equalsIgnoreCase("Exit")) break;
         else //GameLogic
    }
    

    Though, if I may say so, you should have the user choose a number, since any letter input is prone to errors.

    For clarification purposes:

    import java.util.Scanner;   
    
    public class RockPaperScissors{   
        public static void main(String[] args) {
    
            Scanner input = new Scanner(System.in);
    
            int compGoInt;
            String compGo;
            String playerGo;
    
            while(true) {
                System.out.println("You can type 'Exit' to quit the game at any time.");
                System.out.print("Please enter your choice. Rock, Paper or Scissors: ");
                playerGo = input.nextLine();
    
                if(playerGo.equalsIgnoreCase("Exit")) break;    //Checks for exit condition.
                else { //GameLogic
    
                    compGoInt = (int) (Math.random() * 3);
    
                    switch (compGoInt){
                    case 0:
                        compGo = "Rock";
                        break;
                    case 1:
                        compGo = "Paper";
                        break;
                    case 2:
                        compGo = "Scissors";
                        break;
                    default:
                        compGo = "Error";
                        System.out.println("Error.");
                        break;
                    }
    
                    if (playerGo.equals(compGo)){
                        System.out.println("Computer chooses "+compGo);
                        System.out.println("It's a draw!");
                    }
    
                    else if ((playerGo.equalsIgnoreCase("Rock") && compGo.equalsIgnoreCase("Scissors")) ||
                            (playerGo.equalsIgnoreCase("Paper") && compGo.equalsIgnoreCase("Rock")) ||
                            (playerGo.equalsIgnoreCase("Scissors") && compGo.equalsIgnoreCase("Paper"))){
                        System.out.println("Computer chooses "+compGo);
                        System.out.println("Player Wins!");
                    }
    
                    else if ((compGo.equalsIgnoreCase("Rock") && playerGo.equalsIgnoreCase("Scissors")) ||
                            (compGo.equalsIgnoreCase("Paper") && playerGo.equalsIgnoreCase("Rock")) ||
                            (compGo.equalsIgnoreCase("Scissors") && playerGo.equalsIgnoreCase("Paper"))){
                        System.out.println("Computer chooses "+compGo);
                        System.out.println("Computer Wins!");
                    }
    
                    else{
                        System.out.println("Something has gone wrong!");
                        System.out.println("Player chose "+playerGo);
                        System.out.println("Computer chose "+compGo);
                    }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have programmed a simple Jquery ticker (using a pre-made Javascript) to display tweets
I have programmed a simple C# program which creates random string and calculates the
I have a webservice programmed in coldfusion which I'm attempting to consume using c#.net.
Hay guys I've programmed a very simple range finder. The user can only select
I have programmed a simple app that every X minutes checks if an image
I have programmed a simple hibernate app which isn't updating the table. The following
I have programmed a simple hibernate app which leaves me with errors. The following
I'm working on a textbased simple roleplaying game for my exame, but i have
I've created a simple game where 2 players make a simultaneous choice in each
I have programmed a very simple script with jQuery. The idea is to fade

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.