Advertisement
Guest User

opg14

a guest
Sep 25th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Exercise_Pg462_14{
  5.  
  6. public static void main(String[] args)throws FileNotFoundException{
  7. Scanner read = new Scanner(new File("Exercise_Pg_462_14_input.txt"));
  8.  
  9. printDuplicates(read);
  10. }
  11.  
  12. public static void printDuplicates(Scanner read){
  13.  
  14. while (read.hasNextLine()){
  15. String line = read.nextLine();
  16.  
  17. Scanner lineScan = new Scanner(line);
  18.  
  19. int count = 1;
  20. String word1 = "";
  21.  
  22. while (lineScan.hasNext()){
  23. String word2 = lineScan.next();
  24. //System.out.print(word2);
  25. if (word2.equals(word1)){
  26. count++;
  27. //System.out.print(". a.\n");
  28. }
  29. if ((!word2.equals(word1) || !lineScan.hasNext()) && count > 1){
  30. System.out.print(word1 + "*" + count + " ");
  31. word1 = word2;
  32. count = 1;
  33. //System.out.print(". b.\n");
  34. }
  35. if (!word2.equals(word1) && count == 1){
  36. word1 = word2;
  37. //System.out.print(". c.\n");
  38. }
  39. }
  40. System.out.println();
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement