int userInput;
Random randomNumbers = new Random();
numberOne = randomNumbers.nextInt(100);
System.out.print("Enter 0 for even or 1 for odd: ");
userInput = keyboard.nextInt();
label:
while (userInput == 0)
{
if (userInput % 2 == 0)
if (numberOne % 2 == 0)
{
System.out.println("Congradulations!");
userInput--;
}
}
while (userInput == 1)
{
if (userInput % 2 != 0)
if (numberOne % 2 != 0)
{
System.out.println("Congradulations!");
userInput--;
}
}
When the input equals the number it says congratulations but when the input is incorrect it does not ask the user for another number.
Aucun commentaire:
Enregistrer un commentaire