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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:47:04+00:00 2026-06-14T00:47:04+00:00

Here’s my code so far (well, the while loop): public class Lab10d { public

  • 0

Here’s my code so far (well, the while loop):

public class Lab10d
{
public static void main(String args[])
{
    Scanner keyboard = new Scanner(System.in);
    char response = 0;


    //add in a do while loop after you get the basics up and running

        String player = "";

        out.print("Rock-Paper-Scissors - pick your weapon [R,P,S] :: ");

        //read in the player value
        player = keyboard.next();

        RockPaperScissors game = new RockPaperScissors(player);
        game.setPlayers(player);
        out.println(game);
    while(response == ('y'))
    {
        out.print("Rock-Paper-Scissors - pick your weapon [R,P,S] :: ");
        player = keyboard.next();
        game.setPlayers(player);
        //game.determineWinner();
        out.println(game);
        out.println();

        //



    }
    out.println("would you like to play again? (y/n):: ");
        String resp =  keyboard.next();
        response = resp.charAt(0);
}
}

it’s supposed to run the code additional times until an n is inputted

When I input a y, it is supposed to re-run the code but doesn’t

  • 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-14T00:47:06+00:00Added an answer on June 14, 2026 at 12:47 am

    Your while loop ends before you ask if they want to play again.

    Change the loop to:

    while(response == ('y'))
        {
            out.print("Rock-Paper-Scissors - pick your weapon [R,P,S] :: ");
            player = keyboard.next();
            game.setPlayers(player);
            //game.determineWinner();
            out.println(game);
            out.println();
            out.println("would you like to play again? (y/n):: ");
            String resp =  keyboard.next();
            response = resp.charAt(0);
        }
    

    There is another problem: response is not set to ‘y’ before the loop is started. It will not do anything in the loop at all. Use a do { ... } while (response == 'y') loop instead.

        do
        {
            out.print("Rock-Paper-Scissors - pick your weapon [R,P,S] :: ");
            player = keyboard.next();
            game.setPlayers(player);
            //game.determineWinner();
            out.println(game);
            out.println();
            out.println("would you like to play again? (y/n):: ");
            String resp =  keyboard.next();
            response = resp.charAt(0);
        } while (response == 'y');
    

    A do-while will execute the code once, then check the condition and keep executing if it is true. A while loop will just check the condition, and keep executing while it’s true.

    EDIT: I put together some code for you:

    import java.util.Scanner;
    
    public class Troubleshoot {
    
        public static void main(String[] args) {
            Scanner s = new Scanner(System.in);
            char response = ' ';
            do {
                System.out.println("Stuff");
                System.out.print("Again? (y/n): ");
                response = s.next().charAt(0);
            } while (response == 'y');
        }
    
    }
    

    Output:

    Stuff
    Again? (y/n): y
    Stuff
    Again? (y/n): y
    Stuff
    Again? (y/n): n
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my class: public class A{ private void doIt(int[] X, int[] Y){ //change
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
here is my php code $titikPetaInti = array(); while($row = mysql_fetch_assoc($hasil2)) { $titikPetaInti[] =
here is my code, SiteMember class @OneToMany(mappedBy = member,cascade=CascadeType.ALL) private List<MemberThread> memberThread = new
Here's my test function (c#, visual studio 2010): [TestMethod()] public void TestGetRelevantWeeks() { List<sbyte>
Here's what I am trying. MinGW g++ 4.7.0. #include <iostream> #include <string> class Fruit
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the code in a function I'm trying to revise. This example works
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is an example: I write html code inside of textarea, then I swap

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.