[POO] aula12 ex1 added

This commit is contained in:
TiagoRG 2023-05-15 21:27:50 +01:00
parent 75db9ce3fa
commit 0aa8161b00
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
1 changed files with 22 additions and 0 deletions

View File

@ -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<String> words = new ArrayList<>();
while (reader.hasNext()) words.add(reader.next());
HashSet<String> differentWords = new HashSet<>(words);
System.out.println("Number of words: " + words.size());
System.out.println("Number of different words: " + differentWords.size());
}
}