For loop not working correctly in Rock Paper Scissors Java program

rock paper scissors java while loop
rock, paper scissors java 2 players
rock paper scissors java code using methods
rock paper scissors java eclipse
rock paper scissors java switch
rock paper scissors java play again
design and implement an application that plays the rock-paper scissors game against the computer
rock paper scissors java github

I'm new to programming and have been attempting to code a simple Rock Paper Scissors game in Java, but I'm stuck with two problems. The game worked correctly prior to me adding a for loop in order to make the game last for 5 rounds each time, but now with the loop it just repeats the same result line 4 times after entering 1 input, rather than allowing me to enter more inputs and generate several results. I also tried putting in an invalid input message, where if the user inputs anything other than 1, 2 or 3 the program outputs "Invalid user input.", but this doesn't work when ran and has just resulted in compiler error messages.

Any help would be greatly appreciated, thanks!

Here is the entirety of my code:

import java.util.Random;
import java.util.Scanner;

public class RockPaperScissors {

    public static final int ROCK = 1;
    public static final int PAPER = 2;
    public static final int SCISSORS =3;

    public static void main(String[] args) {
        System.out.println("Let's play Rock, Paper, Scissors! (best out of 5)");

        System.out.println("Enter either 1 for Rock, 2 for Paper or 3 for Scissors.");
        Scanner input = new Scanner(;
        int numberGuessed = input.nextInt();

        Random generator = new Random();
        int computerNumber = generator.nextInt(3) + 1;

        for (int round = 0; round < 4; round++) {
            if (numberGuessed == computerNumber) {
            System.out.print("It's a tie!");

        if (numberGuessed == 1 && computerNumber == 2) {
            System.out.println("You lose! I chose paper and paper smothers rock!");
        else if (numberGuessed == 1 && computerNumber == 3) {
            System.out.println("You win! I chose scissors and rock smashes scissors!");
        else if (numberGuessed == 2 && computerNumber == 1) {
            System.out.println("You win! I chose rock and paper smothers rock!");
        else if (numberGuessed == 2 && computerNumber == 3) {
            System.out.println("You lose! I chose scissors and scissors cut paper!");
        else if (numberGuessed == 3 && computerNumber == 2) {
            System.out.println("You win! I chose paper and scissors cut paper!");
        else if (numberGuessed == 3 && computerNumber == 1) {
            System.out.println("You lose! I chose rock and rock smashes scissors!");
        else if (numberGuessed != 1 || numberGuessed != 2 || numberGuessed != 3) {
            System.out.println("Invalid user input.");

[Beginner]How do i make this Rock, Paper, Scissors game loop so i , I've not been able to get it to work properly, a solution and explanation would be brilliant, thanks. How to Run While loop only 3 times in java program? Need Some Guidance if possible please. New to Java. Not to sure why code below for rocks, papers , scissors game is not working. Any suggestions please or advice would be most welcome. I know there are plenty of examples on this great forum - but i am still grasping the basics. Thank you.

You set numbers and do 5 rounds on the same data. Move initialization of numberGuessed and computerNumber inside for loop.

Does my Rock Paper Scissors game look good?, public class RockPaperScissors { static int cScore, pScore, tie, rounds; enum RPS about the Score which is another "thing" that exists in your program, yet there is no You're using the variable 'loop' which has a type of String as a boolean, to read code understands what that code does; so try not to document the what,  I'm having to make a paper rock scissors program that has the user enter in a choice, then tests it against the computer's choice. After every game, it should ask the player if they want to continue, and they should enter in 'Y' or 'N' to continue or quit. The best I could think was a while loop, and everything works fine except the very last bit.

Observe where your input and random number generator is. Think if that will repeat 5 times when your loop runs. Done?

If you haven't observed yet, let me elaborate: your input and random number generator is outside you for loop. That's IT.

Beginner Rock, Paper, Scissors in Java, There are plenty of rock-paper-scissors implementations in java on this site. 0) loop would best be written as a do-while loop, since you want to run the in there and correct a user or at least stop them from crashing the program. Another notable problem with your game is that it will never stop. int b in  The winner is determined by the hand formations. Scissors beats paper, paper beats rock, and rock beats scissors. If both players play the same hand formation, it is considered a tie. We will write a simple game in Java to simulates Rock, Paper, Scissors where one player is the user and the other player is the computer.

FAQs, including common questions/answers/errors for Rock Paper , Loop syntax is almost identical to that of if/else statements, so if you've got those down, Let's say I entered “dog” instead of rock, paper, or scissors. It does not take my userChoice, which is correct and compare it to the computerChoice This should work as well in java and C/C++ (probably in C# as well idk) although​  It is a two-player game in which each person simultaneously chooses either rock, paper, or scissors. Rock beats scissors but loses to paper, paper beats rock but loses to scissors, and scissors beats paper but loses to rock. The following code prompts player 1 and player 2 to each enter a string: rock, paper, or scissors.

Solved: In Chapter 5, you created a Rock Paper Scissors game. I , Answer to In Chapter 5, you created a Rock Paper Scissors game. In the game, a player Java Programming (7th) edition 1285081951 9781285081953. im writting a very easy program that plays rock, paper, scissors. The user plays against the computer as the computer generates a random number that represents rock, paper, or scissors. Everything is working ok except in the end im using nested if-else statements to compare the computer's play to the users and display who won and why. Ex.

Rock-paper-scissors, Implement the classic children's game Rock-paper-scissors, as well as a simple loop. C := Computer_Choice; -- the computer makes its choice first enter "r" for Rock, "p" for Paper, or "s" for Scissors"! or enter "q" to Quit the I´ve created a GUI to play and show results, no Console Input import java.util. Question: Write A Program That Simulates Rock, Paper, Scissors In Java. Rules Of The Game Are As Follows: · Rock Smashes Scissors · Paper Covers Rock · Scissors Cuts Paper You Are To Write A Program That Plays The Game Against The Computer Allow The User To Input Their Name The Computer Should Choose An Object Randomly And Your Program Should Prompt The User