Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void printDuplicates (Scanner input){
- while(input.hasNextLine()){
- Scanner line=new Scanner (input.nextLine());
- String first=line.next();
- String second=line.next();
- while(line.hasNext()){
- int x=0;
- while(first.equals(second)){
- x++;
- first=second;
- if(line.hasNext())
- second=line.next();
- else
- second = "";
- }
- if(x>0){
- System.out.print(first+"*"+(x+1)+" ");
- first=second;
- if(line.hasNext())
- second=line.next();
- else
- second = "";
- }
- if(x==0){
- first=second;
- if(line.hasNext())
- second=line.next();
- else
- second = "";
- }
- }
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment