So I got this far
import javax.swing.JOptionPane;
public class GuessingGame {
public static void main (String [] args) {
int num1 = (int) (System.currentTimeMillis()%10);
String answerString = JOptionPane.showInputDialog(null,"Guess a number between 1 and 10");
int answer = Integer.parseInt(answerString);
if (answer > num1)
JOptionPane.showMessageDialog(null,"Your answer is too high");
else if (answer < num1)
JOptionPane.showMessageDialog(null, "Your answer is too low");
else
JOptionPane.showMessageDialog(null, "You won!");
}
}
This program I am making is a guessing game. The user needs to guess a number between 1 and 10. If the user guesses too high or too low then try again. How do I make the user try again without starting over? Anyone want to give me hints and I try my best to solve it. I was going to make the last part of the program look like this but I don't know.
if (answer > num1)
JOptionPane.showMessageDialog(null,"Your answer is too high");
String answerString = JOptionPane.showInputDialog(null,"Guess a number between 1 and 10");
int answer = Integer.parseInt(answerString);
else if (answer < num1)
JOptionPane.showMessageDialog(null, "Your answer is too low");
String answerString = JOptionPane.showInputDialog(null,"Guess a number between 1 and 10");
int answer = Integer.parseInt(answerString);
else
JOptionPane.showMessageDialog(null, "You won!");
This gave me errors and I don't think this is the right way to do it. NO LOOPS =D