Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your <code>while</code> loop ends before you ask if they want to play again.</p> <p>Change the loop to:</p> <pre><code>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); } </code></pre> <p>There is another problem: <code>response</code> is not set to 'y' before the loop is started. It will not do anything in the loop at all. Use a <code>do { ... } while (response == 'y')</code> loop instead.</p> <pre><code> 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'); </code></pre> <p>A do-while will execute the code <em>once</em>, <strong>then</strong> check the condition and keep executing if it is <code>true</code>. A while loop will just check the condition, and keep executing while it's <code>true</code>.</p> <p>EDIT: I put together some code for you:</p> <pre><code>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'); } } </code></pre> <p>Output:</p> <pre><code>Stuff Again? (y/n): y Stuff Again? (y/n): y Stuff Again? (y/n): n </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload