Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Repetition2 {
  5.  
  6.  
  7. private String isRepeated(String file) throws FileNotFoundException {
  8.  
  9. HashSet<String> words = new HashSet<String>();
  10. String[] wordsArray = file.split(" ");
  11.  
  12. if (wordsArray.length != 0) {
  13. for (String word : wordsArray) {
  14. if (!words.contains(word)) {
  15. words.add(word);
  16. } else
  17. return "no";
  18. }
  19. return "yes";
  20. }
  21.  
  22. return "File empty";
  23.  
  24. }
  25.  
  26. public static void main(String[] args) throws FileNotFoundException {
  27.  
  28. Scanner sc = new Scanner(System.in);
  29.  
  30. Repetition2 r = new Repetition2();
  31.  
  32. String answer = r.isRepeated("/Users/mariasamo/oop/ALDA/src/test2.txt");
  33. // String answer = r.isRepeated(sc.nextLine());
  34.  
  35. System.out.println(answer);
  36.  
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement