Handling Invalid Input in Rock Paper Scissors Game

That’s a solid approach, Babita! If you’re aiming for a more user-friendly experience, you could take it a step further by using a loop that keeps asking the user until they enter a valid move. This avoids having to restart the game just for a typo. Here’s how you can implement it:

while (!personPlay.equals("R") && !personPlay.equals("P") && !personPlay.equals("S")) {
    System.out.println("Invalid move. Try again.");
    personPlay = scan.next().toUpperCase();
}

This will continuously prompt the user until they enter one of the valid moves, keeping the game flowing smoothly. Definitely an improvement for a better experience in rock paper scissors java.