// human guesses a randomly generated number. import javax.swing.*; public class guess1 { public static void main(String[] args) { int n; // random number to be guessed by human String input; // user input in string form int guess = -1; // user input in int form int c = 0; // counts how many times human had to guess. // generate random 1-1024 n = (int)(Math.random() * 1024) + 1; JOptionPane.showMessageDialog(null,"The number is between 1 and 1024"); while (guess != n) { input = JOptionPane.showInputDialog(null,"What's your guess?"); guess = Integer.parseInt(input); if (n < guess) JOptionPane.showMessageDialog(null,"The number is smaller"); if (n > guess) JOptionPane.showMessageDialog(null,"The number is larger"); c = c+1; } // while JOptionPane.showMessageDialog(null,"You guessed it in "+c+" tries!"); System.exit(0); } }