sedran

printDuplicates

Dec 20th, 2010
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1.     public static void printDuplicates (Scanner input){
  2.         while(input.hasNextLine()){
  3.             Scanner line=new Scanner (input.nextLine());
  4.             String first=line.next();
  5.             String second=line.next();
  6.             while(line.hasNext()){
  7.                 int x=0;
  8.                 while(first.equals(second)){
  9.                     x++;
  10.                     first=second;
  11.                     if(line.hasNext())
  12.                         second=line.next();
  13.                     else
  14.                         second = "";
  15.                 }
  16.                 if(x>0){
  17.                     System.out.print(first+"*"+(x+1)+" ");
  18.                     first=second;
  19.                     if(line.hasNext())
  20.                         second=line.next();
  21.                     else
  22.                         second = "";
  23.  
  24.                 }
  25.                 if(x==0){
  26.                     first=second;
  27.                     if(line.hasNext())
  28.                         second=line.next();
  29.                     else
  30.                         second = "";
  31.  
  32.                 }
  33.             }
  34.             System.out.println();
  35.         }
  36.     }
Add Comment
Please, Sign In to add comment