From 0aa8161b00d94252bb62080e73ac9db57a803354 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Mon, 15 May 2023 21:27:50 +0100 Subject: [PATCH] [POO] aula12 ex1 added --- .../src/aula12/ex1/DifferentWordCounter.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 1ano/2semestre/poo/src/aula12/ex1/DifferentWordCounter.java 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()); + } +}