title: Getting Exception within reading dates in java
body: <p>I'm solving a problem that, given the initial date and the final date, returns the number of days between them.</p>
  
  <p>I just finished and my answer seems to be correct, but it says that at some input, my method of reading the year fails and it throws an exception.</p>
  
  <p>Here is my code of reading dates and parsing them to integers:</p>
  
  <pre><code>    String si = in.nextLine();
      String sf = in.nextLine();
  
      int di = Integer.parseInt(si.substring(0, 2)); 
      int mi = Integer.parseInt(si.substring(3, 5));
      int ai = Integer.parseInt(si.substring(6, si.length()));
  
      int df = Integer.parseInt(sf.substring(0, 2)); 
      int mf = Integer.parseInt(sf.substring(3, 5));
      int af = Integer.parseInt(sf.substring(6, sf.length()));
  </code></pre>
  
  <p>The dates are given in format XX/XX/XXXX (just for security, I read the year using s.length to cover cases of year being &lt;1000 or >9999)</p>
  
  <p>What in this code can throw an exception at reading years at that format?</p>