title: How to count valid and invalid lines in file
body: <p>I have the following code:  </p>
  
  <pre><code>public class generator {
  
  
  public static void main(String[] args) throws FileNotFoundException {
  
  
      Scanner s = new Scanner(new File("results.txt"));// creates a scanner to
                                                          // scan from a file
      String line;
      String HomeTeam, AwayTeam;
      while (s.hasNext()) {
          line = s.nextLine(); // reads the next line from the file
          line = line.trim(); // trims the line
          String[] elements = line.split(":"); // splits the line
          if (elements.length == 4) {
              HomeTeam = elements[0].trim(); // trims home team
              AwayTeam = elements[1].trim(); // trims away team
              elements[2] = elements[2].trim();
              elements[3] = elements[3].trim();
  
              if (HomeTeam.length() != 0 &amp;&amp; AwayTeam.length() != 0) { // check if position is present
                  try {   // "try" is a special statement which allows us to deal with "exceptions"
  
                      int HomeScore = Integer.parseInt(elements[2]);  // attempt to convert the String into an Integer type value
                      int AwayScore = Integer.parseInt(elements[3]);
                      System.out.println(HomeTeam + " ["+ HomeScore +"]" + " | " + AwayTeam + " ["+AwayScore+"]");
                  }
                  catch (NumberFormatException e) {
  
                  }
  
              }
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Now my question is: how do I count the valid and invalid lines as well as total number of score in entire file?  </p>
  
  <p>Sample input file is:<br>
  Leeds United : Liverpool : 1 : 2<br>
  Chelsea :  Manchester City : 1 : 1<br>
  Aston Villa : Middlesbrough : 3 : 1<br>
  Tottenham Hotspur : Stoke City : 0 : 0<br>
  West Ham United : Wigan Athletic :2 : 1<br>
  Fulham : Liverpool : 1 : 2<br>
  Wigan Athletic : Leeds United : 2 : 2<br>
  Arsenal Liverpool :2:2<br>
  Hull City: Tottenham Hotspur : 3 : 5<br>
  Everton : Portsmouth:4 : 2<br>
  Stoke City : West Bromwich Albion : 5 : 4<br>
  Leeds United : Liverpool : 1: 10<br>
  Blackburn Rovers : Fulham : 1 : 1<br>
  West Ham United : Newcastle United : 0 : 0<br>
  Manchester United : Wigan Athletic : 1 : 2<br>
  Hull City : Sunderland : 2 : 3<br>
  Chelsea : Manchester City :1<br>
  Fulham : Leeds United : 1 : 2<br>
  Wigan Athletic : Tottenham Hotspur : 2 : 2<br>
  Hull City : Everton : 3 : 5<br>
  : :2:0<br>
  Sunderland : Blackburn Rovers : 4 : 2<br>
  Stoke City : West Bromwich Albion : 5 : 4<br>
  Hull : Liverpool : 5: x<br>
  Blackburn Rovers : Fulham : 1 : 1<br>
  Chelsea  : Everton : a : 1<br>
  Sunderland : Newcastle United : 0 : 0<br>
  Hull : :2:3<br>
  Sunderland : Blackburn Rovers : 1 : 2<br>
  Hull City : Everton : 2 : 3<br>
  Leeds United : Chelsea : 1 : 2<br>
  Chelsea : Manchester City : 1 : 1<br>
  Aston Villa:Fulham:3:1<br>
  Manchester City : Stoke City : 0 : 0<br>
  West Ham United : Middlesbrough : 2 : 1  </p>