-bash-4.1$ cat sample.txt
     This is

   a

test.


-bash-4.1$ cat Seventeen.java
import java.io.*;
import java.util.*;

class Seventeen {
  public static void main(String[] args) throws Exception {
    Scanner a = new Scanner(new File(args[0]));
    int count, nonspace = 0, tokens = 0;
    double lines = 0;
    for (count = 0; a.hasNextLine(); ) {
      String line = a.nextLine();
      System.out.println("***(" + line + ")***");
      lines = lines + 1;
      for (int i = 0; i < line.length(); i = i + 1) {
        String c = line.substring(i, i + 1);
        if (c.trim().equals("")) {
          count = count + 1;
        } else {
          count = count + 1;
          nonspace = nonspace + 1;
        }
      }
      Scanner t = new Scanner(line);
      while (t.hasNext()) {
        tokens += 1;
        t.next();
      }
    }
    System.out.println("Number of lines: " + lines);
    System.out.println("Average line in non-space chars: " + (nonspace / lines));
    System.out.println("Average line in total chars: " + (count + lines) / lines);
    System.out.println("Number of words: " + tokens);
    System.out.println("Average line in words: " + tokens / lines);

  }
}
-bash-4.1$ javac Seventeen.java
-bash-4.1$ java Seventeen
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
        at Seventeen.main(Seventeen.java:6)
-bash-4.1$ java Seventeen sample.txt
***(     This is )***
***(   )***
***(   a )***
***( )***
***(test.)***
***(      )***
***(         )***
Number of lines: 7.0
Average line in non-space chars: 1.7142857142857142
Average line in total chars: 7.0
Number of words: 4
Average line in words: 0.5714285714285714
-bash-4.1$