I have a question: how do I validate that the value entered in the correct range and ask the user to reenter the choice? I already have the code listed below but it keeps looping instead. For example, if player 1 enters 6, it should say incorrect, re-enter the correct number, and when player 1 enter a number between 1 and 5, it goes on to player 2 and repeats. My problem is the loop I used is not allowing me to do so, instead it is looping my print statement 5 times.
import java.util.Scanner;
import java.util.Random;
public class Moropinzee
{
public class void main(String[] args)
{
String personPlay;
int computerInt;
String response;
int Monkey = 1;
int Robot = 2;
int Pirate = 3;
int Ninja = 4;
int Zombie = 5;
Scanner scan = new Scanner(System.in);
Random generator = new Random();
System.out.print("Hey, let's play Moropinzee!\n" +
"Please enter a move.\n");
System.out.println("Player 1: Enter a number 1-5 for Monkey, Robot, Pirate, Ninja, or Zombie:");
String player1 = scan.next().toUpperCase();
System.out.println("Player 2: Enter a number 1-5 for Monkey, Robot, Pirate, Ninja, or Zombie");
String player2 = scan.next().toUpperCase();
System.out.println();
for(int number = 0; number < 5; number++)
{
System.out.println("Invaild choice, Player 1. Enter a number 1-5:");
}
}
}
I want to give my gratitude on the person who helped me clean up my code. I ran into one problem, if I enter number 1, the code will print invalid try again... Well, you can see on the pictures down below. If I enter 1, it should move onto asking Player 2 to key in a number.
player 1 = nextInt();
if (player 1 =>6)
invalid try again