Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class Exercise_Pg462_14{
- public static void main(String[] args)throws FileNotFoundException{
- Scanner read = new Scanner(new File("Exercise_Pg_462_14_input.txt"));
- printDuplicates(read);
- }
- public static void printDuplicates(Scanner read){
- while (read.hasNextLine()){
- String line = read.nextLine();
- Scanner lineScan = new Scanner(line);
- int count = 1;
- String word1 = "";
- while (lineScan.hasNext()){
- String word2 = lineScan.next();
- //System.out.print(word2);
- if (word2.equals(word1)){
- count++;
- //System.out.print(". a.\n");
- }
- if ((!word2.equals(word1) || !lineScan.hasNext()) && count > 1){
- System.out.print(word1 + "*" + count + " ");
- word1 = word2;
- count = 1;
- //System.out.print(". b.\n");
- }
- if (!word2.equals(word1) && count == 1){
- word1 = word2;
- //System.out.print(". c.\n");
- }
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement