title: Calculating Average from a CSV File
body: <p>I have a CSV file, format as follows:</p>
  
  <p><code>City,Job,Salary
  Delhi,Doctors,500
  Delhi,Lawyers,400
  Delhi,Plumbers,100
  London,Doctors,800
  London,Lawyers,700
  London,Plumbers,300
  Tokyo,Doctors,900
  Tokyo,Lawyers,800
  Tokyo,Plumbers,400
  Lawyers,Doctors,300
  Lawyers,Lawyers,400
  Lawyers,Plumbers,500
  Hong Kong,Doctors,1800
  Hong Kong,Lawyers,1100
  Hong Kong,Plumbers,1000
  Moscow,Doctors,300
  Moscow,Lawyers,200
  Moscow,Plumbers,100
  Berlin,Doctors,800
  Berlin,Plumbers,900
  Paris,Doctors,900
  Paris,Lawyers,800
  Paris,Plumbers,500
  Paris,Dog catchers,400</code> </p>
  
  <p>I want to find the average of the total salaries. </p>
  
  <p>This is my code:</p>
  
  <p>` import java.io.*;</p>
  
  <p>public class A {</p>
  
  <pre><code>public static void main(String args[])
  {
  A a= new A();
  a.run();
  }
  
  public void run()
  {
  String csv="C:\\Users\\Dipayan\\Desktop\\salaries.csv";
          BufferedReader br = null;
  String line = "";
  int sum=0;
  int count=0;
  //String a=new String();
  
  
          try {
  
              br = new BufferedReader(new FileReader(csv));
              try {
                  while ((line = br.readLine()) != null) {
  
                          // use comma as separator
                      String[] country = line.split(",");
                      int sal=Integer.parseInt(country[2]);
                      sum=sum+sal;
                           count++;
                  //System.out.println("Salary [job= " + country[0] 
                                    //        + " , salary=" + country[2] + "]");
  
                  }
              } catch (NumberFormatException | IOException e) {
                  System.out.println("NA");
                  e.printStackTrace();
              }
  
  
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }  
          System.out.println(sum/count);
  
  
          System.out.println("Done");
        }
  
      }` 
  </code></pre>
  
  <p>But, its showing error: </p>
  
  <blockquote>
    <p>java.lang.NumberFormatException: For input string: "Salary"
        at java.lang.NumberFormatException.forInputString(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at A.run(A.java:30)
        at A.main(A.java:9)
    Exception in thread "main" java.lang.ArithmeticException: / by zero
        at A.run(A.java:46)
        at A.main(A.java:9)`</p>
  </blockquote>
  
  <p>Is there any better or short code to parse the CSV file.</p>