title: I need help on verifying wether a date is valid in JAVA I have tried everything but its just not working correctly here my code
body: <p>import java.util.*;</p>
  
  <p>public class DateChecker</p>
  
  <p>These are my directions:</p>
  
  <p>Write a Java application program that will allow the user to enter a date. The program will then check the date to verify whether or not it is a valid date.</p>
  
  <p>Begin by asking the user to enter a date in the form, mm/dd/yyyy. This will be entered as a String, since the date contains slash marks.</p>
  
  <p>After the date is entered, the program should check the date for validity. If the date is valid, the program should display the message "Valid date". If the date is not valid, the program should display the message "Not a valid date" along with a message to indicate why the date is not valid.</p>
  
  <pre><code>public static void main(String[] args) {
  
      Scanner kbd = new Scanner(System.in);
      System.out.println("Enter a date");
      String dateStr = kbd.nextLine();
  
      if(dateStr.length() == 10){
          if (dateStr.charAt(2) == '/' &amp;&amp; dateStr.charAt(5) == '/'){
              String mmStr = dateStr.substring(0, 2);
              String ddStr = dateStr.substring(3, 5);
              String yyyyStr = dateStr.substring(6);
  
              int mm = Integer.parseInt(mmStr);
              int dd = Integer.parseInt(ddStr);
              int yyyy = Integer.parseInt(yyyyStr);
  
              if (mm &lt;= 12 &amp;&amp; mm &gt;=1){
  
                  if (((((mm == 1) &amp;&amp; (dd == 31)) || ((mm == 3) &amp;&amp; (dd == 31)) || ((mm == 4) &amp;&amp; (dd == 30)) || ((mm == 5) &amp;&amp; (dd ==31)) || ((mm == 6) &amp;&amp; (dd == 30)) || ((mm == 7) &amp;&amp; (dd == 31)) || ((mm == 8) &amp;&amp; (dd == 31)) || ((mm == 9) &amp;&amp; (dd == 30)) || ((mm == 10) &amp;&amp; (dd == 31)) || ((mm == 11) &amp;&amp; (dd == 30)) || ((mm == 12) &amp;&amp; (dd == 31))))) 
                  {
                      System.out.println("Vailid date.");
                  }
  
                  else if (mm == 2){
                      if ((yyyy%4==0 &amp;&amp; yyyy%100!=0) ||yyyy%400==0)
                      {
                      if (dd == 29){
                          System.out.println("Valid date");
                      }
                      else {
                          System.out.println("Not a valid date \nDay is not valid");
                      }
                      }
  
                      else {
                          if (dd == 28){
                              System.out.println("Valid date");
                          }
                          else {
                              System.out.println("Not a valid date \nDay is not valid");
                          }
                      }
                  }
                  else 
                  {
                      System.out.println("Not a valid date \nDay is not valid");
                  }
              }else {
                  System.out.println("Not a valid date \nMonth is not valid");
              }
      }
      else {
          System.out.println("Not a valid date \nIncorrect format");
      }
          if (dateStr.length() &gt; 10){
              System.out.println("Too many characters in the date");
          }else {
              System.out.println("Too few characters in the date ");
  
          }
      }
  }
  </code></pre>
  
  <p>}</p>