0

This code is designed to show message if guess variable is equal to lucky variable which has been initialised. So I have created an object in to read the input from the user. So in the if,else loop I have crafted a condition to see if guess is equal to lucky. My program compiles and when I enter a number, it doesnt show the message dialog.I cannot use println() function and only message dialog to be used

public static void main(String[] args) {
    // TODO Auto-generated method stub

    int guess,lucky;
    String strOut=" ";
    lucky = 8;

     Scanner in = new Scanner(System.in);
     System.out.println("Please guess your lucky number: ");

     guess = in.nextInt();

    if(guess == lucky)
    {
        strOut = "Congratulations! ";
    }
    else
    {
        strOut = "Thank you for guessing! ";
    }

    JOptionPane.showMessageDialog(null, strOut);
}

}

Big_Smoke
  • 57
  • 9

1 Answers1

1

you should defineJFrame f = new JFrame(); and use it in JOptionPane.showMessageDialog(f, strOut);

saraafr
  • 1
  • 4
  • 19