Program that reads a string from the keyboard and tests whether it contains a valid date I know this task could be done in more practical ways, but the professor only want us to solve it with the "if" statement. I tested and it meets the condition for each task, but I still feel this code looks a bit awkward, I think there is an easier way to get it done. Can someone give me any advice?

import javax.swing.JOptionPane;
public class ValidDate {

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

        String Smonth =
                JOptionPane.showInputDialog ("Enter the Month");
        int month = Integer.parseInt(Smonth);

        if (month &lt;= 0 || month &gt; 12)
        {
            JOptionPane.showMessageDialog (null, " The month you entered is wrong" );
            System.exit (0);
        }

        String Sday =
                JOptionPane.showInputDialog ("Enter the Day");
        int day = Integer.parseInt(Sday);

         if (day &lt;= 0 || day &gt; 31)
            {
                JOptionPane.showMessageDialog (null, " The day you entered is wrong" );
                System.exit (0);
            }
         else if (month == 4 || month == 6 || month == 9 || month == 11 &amp;&amp; day &gt; 30)
            {
                JOptionPane.showMessageDialog (null, " The day you entered is wrong because " + month + " month has only 30 days");
                System.exit (0);
            }

        String Syear =
                JOptionPane.showInputDialog ("Enter the Year");
        int year = Integer.parseInt(Syear);
        boolean leap = ((year % 4 == 0) &amp;&amp; (year % 100 != 0) || (year % 400 == 0));

         if (leap == false &amp;&amp; month == 2 &amp;&amp; day &gt;=29)
        {
            JOptionPane.showMessageDialog (null, " The Date you entered is wrong since " + year +" is not a leap year" );
            System.exit (0);
        }
        else 
            JOptionPane.showMessageDialog (null, " The Date you entered is " + month + "/" + day + "/" + year);

    }

}
First, a few comments about style. 


You shouldn't start variable names with a capital letter, that's used for constants and class names.  So instead of Smonth and Sday, use monthStr and dayStr.
If you put braces around the statement after an if, put them around the else as well.  Your last if/else doesn't do that.
Instead of saying leap == false, say !leap.  


I think the one thing that could make your code look cleaner and clearer would be to move repeated code off into a separate method.  For example, you're repeatedly opening a JOptionPane, getting a value and then converting it to an integer.  Why not put that in a separate method, so you could call:

int month = getValue("Month");


This would reduce the clutter in your main method and have the added advantage that if you wanted to change how you ask the user for values, you would only have to do it in one place.  Do that with your error checking as well and your code improve quite a bit.