title: Java Valid Dates and JOptionPane
body: <p>Noob here so bear with me..I was working on a Java program that takes the users input from the JoptionPane, and uses a set of if-else statements to verify the date while considering the leap years. The problem I seem to be having when it runs is that it validates dates that aren't possible. For example, 2/29/2014, it says it's a valid date, but in reality it isn't.
  Insight on this issue would be highly appreciated.  </p>
  
  <pre><code> import java.util.Arrays;
   import javax.swing.JOptionPane;
  
   public class vaildDate {
  
  public static void main(String[] args) {
      // TODO Auto-generated method stub
  
  
      int month, day, year;
  
      String userInput = JOptionPane.showInputDialog("Enter a valid date in mm/dd/yyyy format: ");
      String [] date = userInput.split("/");
      String mm = date[0];
      String dd = date [1];
      String yyyy = date  [2];
      month  = Integer.parseInt(mm);
      day = Integer.parseInt(dd);
      year = Integer.parseInt(yyyy);
      System.out.println(mm+dd+yyyy);
  
  
  
      boolean validLeapYear;
      boolean validDate;
      if(month&gt;=1 &amp;&amp; month &lt;=12&amp;&amp; day&gt;=1 &amp;&amp; day&lt;=31)
      {
  
          if(month == 4 || month == 9 || month == 6 || month == 11 &amp;&amp;  day &lt;= 30)
          {
              validDate = true; 
          }
  
          if(( month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 11 || month == 12) &amp;&amp; (day &lt;= 31))
          {
              validDate = true;
          }
          else{ 
              validDate =false; 
  
          }
  
          if((year % 400 == 0 ) || (year % 4 == 0) &amp;&amp; (year % 100 != 0))
          {
  
              validLeapYear = true;
  
          }
          if ((month == 2 &amp;&amp; day == 29) &amp;&amp; (validLeapYear = false ))
          {
              validDate = false;
          }
          if((month == 2 &amp;&amp; day &lt;= 29) &amp;&amp; (validLeapYear = true ))
          {
              validDate = true;
          }
  
  
          if(validDate = true)
          {
              JOptionPane.showMessageDialog(null, month +"/"+day+"/"+year+" is a valid date");
          }
  
          else if(validDate = false) {
              JOptionPane.showMessageDialog(null,"Your date is invalid");
          }
      }
     }
    }
  </code></pre>