diff options
| author | pants <niklasjo2004@gmail.com> | 2026-09-21 14:16:22 -0700 |
|---|---|---|
| committer | pants <niklasjo2004@gmail.com> | 2026-09-21 14:16:22 -0700 |
| commit | 4a0d047e83141d3ebe48a2bf4ea58e1192a01333 (patch) | |
| tree | 7125d1be1df434ca98a1d08fb4a30ebd28730d19 /wordcount.java | |
Diffstat (limited to 'wordcount.java')
| -rw-r--r-- | wordcount.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/wordcount.java b/wordcount.java new file mode 100644 index 0000000..8aba15d --- /dev/null +++ b/wordcount.java @@ -0,0 +1,18 @@ +import java.util.*; +import java.io.*; + +public class wordcount { + public static void main(String[] args) throws FileNotFoundException { + File input = new File(args[0]); + Scanner fileScanner = new Scanner(input); + + int count = 0; + while (fileScanner.hasNext()) { + String nextToken = fileScanner.next(); + count++; + } + + fileScanner.close(); + System.out.println(count); + } +} |
