I am trying to create a program in Java in which the computer randomly guesses a number between 1-100 and allows the user to guess to the number.
If the number is lower
import java.util.Random;
public static void main(String[] args)
{
int a = 1 + (int)(Math.random()*99);
int guess = 0;
int count = 0;
while(guess != a)
{
guess = Integer.parseInt(JOptionPane.showInputDialog("Enter a Number"));
count++;
if (guess > a)
{
JOptionPane.showMessageDialog(null,"lower!");
}
else if (guess < a)
{
JOptionPane.showMessageDialog(null,"higher!");
}
}
JOptionPane.showMessageDialog(null,"Congratulations. You guessed the number with " +count+ " tries");
}
}