RockPaperScissors Help?

RockPaperScissors Help?
0.0 0

#1

I get a weird error from my code:
[line: 62]
Error: Syntax error on token “}”, delete this token

Anyone know how to fix this?

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


public class RockPaperScissors 
{ 
public static void main(String[] args) 
{ 
    String humanChoice; 
    String computerChoice = "";
    int rngInt; 
    String response; 

    Scanner rps = new Scanner(System.in); 
    Random generator = new Random(); 

    System.out.println("It is time to play Rock, Paper, and Scissors!!!\n" + 
                       "Please enter a move.\n" + "Rock = R, Paper" + 
                       "= P, and Scissors = S.");
    System.out.println();
    rngInt = generator.nextInt(3)+1; 
    if (rngInt == 1) 
       computerChoice = "R"; 
    else if (rngInt == 2) 
       computerChoice = "P"; 
    else if (rngInt == 3) 
      computerChoice = "S"; 


    System.out.println("Enter your play: "); 
    humanChoice = rps.next();

   
    humanChoice = humanChoice.toUpperCase(); 

    System.out.println("Computer play is: " + computerChoice); 

   if (humanChoice.equals(computerChoice)) {
   System.out.println("It's a tie!");
}
else if (humanChoice.equals("R")) {
   if (computerChoice.equals("S")) 
      System.out.println("Rock beats scissors. You win.");
   else if (computerChoice.equals("P")) 
        System.out.println("Paper beats rock. You lose.");
}
else if (humanChoice.equals("P")) {
   if (computerChoice.equals("S")) 
       System.out.println("Scissor beats paper. You lose."); 
   else if (computerChoice.equals("R")) 
        System.out.println("Paper beats rock. You win.");
} 
else if (humanChoice.equals("S")) {
     if (computerChoice.equals("P")) 
         System.out.println("Scissor beats paper. You win."); 
     else if (computerChoice.equals("R")) 
        System.out.println("Rock beats scissors. You lose.");
}
else 
     System.out.println("Select a Valid Input.");
} } }

#2

Looks like you just have an extra } at that line (as the error message says)


#3

Thanks but now I have a few more error messages :frowning:
[line: 13]
Warning: The value of the local variable response is not used
[line: 15]
Warning: Resource leak: ‘rps’ is never closed


#4

Not exactly an error. The compiler just warns you that you have an unused variable.

You might want to close that Scanner instance at the end of your code. I don’t think it’s a pressing issue since that instance is using System.in, but for other I/O operations (like reading files), it’s important to close them afterwards. I haven’t done Java in a long time, so I don’t know how to close it.