title: Sum of CSV column in Java
body: <p>I have imported a CSV file into my java application, and I am trying to produce the SUM of one of the columns. However, the result of the SUM that is shown is different to the SUM value I get when i calculate the SUM of the column in Excel Spreadsheet.</p>
  
  <p>I have checked the result of the sum in many different applications and it produces the same result apart from in my java application. There are 3281 lines in my CSV file (this may be a contributing factor). </p>
  
  <pre><code>    String csvFile = "1722_schools-number-on-roll-warwickshire-1998-2010.csv";
      String line = "";
      String cvsSplitBy = ",";
      int sum = 0; 
      int  year1 = 0;
      double numbersenrolled = 0;
  
      try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {
              br.readLine();
  
          while ((line = br.readLine()) != null) {
  
              // use comma as separator
              String[] studentenroll = line.split(cvsSplitBy);
             year1 = Integer.parseInt(studentenroll[9]);
              //debug the fie and each numbers
              sum = sum + year1;
              numbersenrolled++;
  
  
  
              System.out.println("Number of Students Enrolled [Year 1 = " +    year1 + " , Year 2 = " + studentenroll[10] + "]");
  
          }
  
              //sum + median + mean
              System.out.println("Sum: " + sum);
              System.out.println("Average: " + (sum/numbersenrolled) );
              System.out.println(numbersenrolled);
  
      } catch (IOException e) {
          System.out.println("File does not exist");
          e.printStackTrace();
      }
  </code></pre>