0

Hi i'm pretty new to java I've been having an issue when I attempt an "if-else" statement. I get syntax errors, which I'm not sure why. Thanks for your input.

 import javax.swing.JOptionPane;

public class MagicDate {

    public static void main(String [] args){

        int month;
        int day;
        int year;
        String input;
        String message = ("This program will find a secret date");

        JOptionPane.showMessageDialog(null, message);

        input = JOptionPane.showInputDialog( " Enter a month of the in numeric "
                                            + "form");
        month= Integer.parseInt(input);

        input = JOptionPane.showInputDialog( " Enter a day of the in numeric"
                                            + " form");
        day= Integer.parseInt(input);

        input = JOptionPane.showInputDialog( " Enter a two digit year");
        year = Integer.parseInt(input);

        if(month * day == year);
        {
            JOptionPane.showMessageDialog(null, "The Date is Magic!");
        }
        else 
        {
            (month * day != year);
            JOptionPane.showMessageDialog(null, "The Date is not Magic");
        }   
        System.exit(0);

    }
}
1
  • 1
    if(month * day == year); dont use ; after if condition. Commented Feb 25, 2015 at 5:03

3 Answers 3

2

You should remove the semicolon at the end of the line containing the if statement. Basically, the effect of the semicolon is adding an empty statement. So your code reads like this to the compiler:

If (...)
   Do nothing;
// can't have an brace here since the if statement has already terminated.
{
   ...
}
Sign up to request clarification or add additional context in comments.

Comments

0

Remove the semicolon:

if(month * day == year)

Comments

0

Remove ; after if condition

if(month * day == year); // remove ;

and missing if

else 
{
    (month * day != year); // add if before line and remove ;
    JOptionPane.showMessageDialog(null, "The Date is not Magic");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.