diff --git a/1ano/2semestre/poo/src/aula12/ex1/DifferentWordCounter.java b/1ano/2semestre/poo/src/aula12/ex1/DifferentWordCounter.java new file mode 100644 index 0000000..ed4681e --- /dev/null +++ b/1ano/2semestre/poo/src/aula12/ex1/DifferentWordCounter.java @@ -0,0 +1,22 @@ +package aula12.ex1; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Scanner; + +public class DifferentWordCounter { + public static void main(String[] args) throws FileNotFoundException { + Scanner reader = new Scanner(new FileReader((new Scanner(System.in)).nextLine())); + List words = new ArrayList<>(); + + while (reader.hasNext()) words.add(reader.next()); + + HashSet differentWords = new HashSet<>(words); + + System.out.println("Number of words: " + words.size()); + System.out.println("Number of different words: " + differentWords.size()); + } +}