// Helene Martin, CSE 142 // Counts the number of words on each line and reports the total words in the file. import java.io.*; import java.util.*; public class LineCounter { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("jabberwocky.txt")); int totalWords = 0; while (input.hasNextLine()) { String line = input.nextLine(); int words = countWords(line); System.out.println("Line has " + words + " words"); totalWords += words; } System.out.println("Total words: " + totalWords); } // Counts words in a particular String public static int countWords(String line) { Scanner lineScan = new Scanner(line); int count = 0; while (lineScan.hasNext()) { count++; lineScan.next(); } return count; } }