Im in AP computer science as a high school student. I was bored so i decided to write a rock paper scissor code. It runs a while loop to play a few games in a row and determine a winner, but the first run on the while loop doesnt take in the user input. Its as if the user = scan.nextLine doesnt work on the first run
Scanner scan = new Scanner (System.in);
String answer = "none";
System.out.println("How many games of Rock, Paper, Scissors would you like to play?");
int games = scan.nextInt();
int count = 0;
int computerWins = 0;
int userWins = 0;
int computer = 0;
String user = " ";
while (count < 10)
{
System.out.println("Enter Rock, Paper, or Scissors");
user = scan.nextLine();
computer = ((int)(Math.round((Math.random () * 2) + 1)));
if (computer == 1)
{
answer = "Rock";
}
else if (computer == 2)
{
answer = "Paper";
}
else if (computer == 3)
{
answer = "Scissors";
}
System.out.println("The Computer Chose: " + answer);
if ((answer.equals("Rock")) && (user.equals("Scissors")))
{
System.out.println("The Computer's Rock beats your Scissors");
computerWins++;
}
else if ((answer.equals("Paper")) && (user.equals("Rock")))
{
System.out.println("The Computer's Paper beats your Rock");
computerWins++;
}
else if ((answer.equals("Scissors")) && (user.equals("Paper")))
{
System.out.println("The Computer's Scissors beat your Paper");
computerWins++;
}
else if (answer.equals(user))
System.out.println("TIE! Your " + user + " is the same as the Computer's " + answer);
else
{
System.out.println("Your " + user + " beats the Computer's " + answer);
userWins++;
}
count++;
System.out.println("Score Stands: Computer " + computerWins + " You " + userWins);
}