Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class Repetition2 {
- private String isRepeated(String file) throws FileNotFoundException {
- HashSet<String> words = new HashSet<String>();
- String[] wordsArray = file.split(" ");
- if (wordsArray.length != 0) {
- for (String word : wordsArray) {
- if (!words.contains(word)) {
- words.add(word);
- } else
- return "no";
- }
- return "yes";
- }
- return "File empty";
- }
- public static void main(String[] args) throws FileNotFoundException {
- Scanner sc = new Scanner(System.in);
- Repetition2 r = new Repetition2();
- String answer = r.isRepeated("/Users/mariasamo/oop/ALDA/src/test2.txt");
- // String answer = r.isRepeated(sc.nextLine());
- System.out.println(answer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement