fork(3) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String text = "Текст#abc\nТекст#abc\nТекст#abc";
  13. String toReplace = "abc";
  14.  
  15. System.out.println(text);
  16. System.out.println();
  17.  
  18. int number = 1;
  19.  
  20. while (text.contains(toReplace)) {
  21. text = text.replaceFirst(toReplace, "" + number);
  22. number++;
  23. }
  24.  
  25. System.out.println(text);
  26. }
  27. }
Success #stdin #stdout 0.09s 27964KB
stdin
Standard input is empty
stdout
Текст#abc
Текст#abc
Текст#abc

Текст#1
Текст#2
Текст#3