enter image description here System.out.println("Welcome to Rock, Paper Scissors!");
// User enters the number of rounds they want to play
// Rounds range from 1(min) to 10 (max)
System.out.println("Let's begin with the number of rounds you would like to play: " );
stringRounds = sc.nextLine();
int rounds = Integer.parseInt(stringRounds);
while (rounds < 1 || rounds > 10) {
System.out.println(stringRounds + (" is out of my range. Please try again."));
stringRounds = sc.nextLine();
rounds = Integer.parseInt(stringRounds);
}
System.out.println(stringRounds + (" sounds good to me. Let's Get Started!"));
int compChoice = rnd.nextInt();
switch (compChoice) {
case 1:
randomChoice = "Rock";
break;
case 2:
randomChoice = "Paper";
break;
case 3:
randomChoice = "Scissors";
break;
default:
break;
}
// User will choose Rock, Paper, or Scissors
System.out.println("Pick your move: Rock, Paper, Scissors?");
int userChoice = sc.nextInt();
//t userChoice = Integer.parseInt(stringUser);
if (userChoice == compChoice) {
System.out.println("IT'S A TIE!!");
}
else if ("Rock".equals(userChoice))
if ("Scissors".equals(compChoice))
System.out.println (("Rock breaks Scissors!") + userChoice + (" wins this round!"));
else if ("Paper".equals(compChoice))
System.out.println(("Paper wraps Rock!") + compChoice + (" wins this round!"));
else if ("Paper".equals(userChoice))
if ("Rock".equals(compChoice))
System.out.println(("Paper wraps Rock!") + userChoice + (" wins this round!"));
else if ("Scissors".equals(compChoice))
System.out.println(("Scissors cuts Paper") + compChoice + (" wins this round!"));
else if ("Scissors".equals(userChoice))
if ("Paper".equals(compChoice))
System.out.println(("Scissors cuts Paper") + userChoice + (" wins this round!"));
else if ("Rock".equals(compChoice))
System.out.println(("Rock breaks Scissors!") + compChoice + (" wins this round!"));
else
System.out.println("Invalid user input!");
}
"Exception in thread "main" java.util.InputMismatchException"
It lets me enter number of rounds, but it doesn't execute when I enter User's choice. I tried debugging and it's not really showing me what the error is. Unless I'm debugging wrong(most likely).
Aucun commentaire:
Enregistrer un commentaire