Код в порядке, но я пытаюсь создать код, чтобы попросить игрока воспроизвести его снова, если игрок хочет воспроизвести снова, код продолжит работу. Но этого не произошло.
package exercise;
import javax.swing.JOptionPane;
import java.util.Random;
public class guessing_game {
public static void main(String[] args) {
Random random = new Random();
int randomNumber = random.nextInt(101);
boolean userCorrect = false;
String userInputString;
int userGuessedNumber;
int count = 0;
String play= "n", UserCorrect="y" ;
do {
count=count+1;
userInputString =JOptionPane.showInputDialog("Guess the number:");
userGuessedNumber =Integer.parseInt( userInputString );
if( userGuessedNumber > randomNumber) {
JOptionPane.showMessageDialog( null, "Too high, try again");
}
else if( userGuessedNumber < randomNumber) {
JOptionPane.showMessageDialog( null, "Too low, try again");
}
else {
JOptionPane.showMessageDialog( null, "Yes, you guessed the number, the guessed number is: " + randomNumber);
JOptionPane.showMessageDialog( null, "The number your guessed is " + count);
userCorrect =true;
play = JOptionPane.showInputDialog("Play again? (y/n) : ");
}
}
while( userCorrect!=true || play == UserCorrect);
}
}