fork download
  1. class Twinkle
  2. { public static void main(String[] args)
  3. { String rhyme = "Twinkle\ntwinkle\nlittle star";
  4. String rhyme2 = process(rhyme, "\n");
  5. System.out.println(rhyme + "\n" + rhyme2);
  6. }
  7. public static String process(String msg, String delim)
  8. { int pos = msg.indexOf(delim);
  9. while (pos >= 0)
  10. {
  11. System.out.println(msg.substring(0, pos) + msg.length());
  12. System.out.println(msg.substring(pos + delim.length()));
  13. //test above
  14. msg = msg.substring(0, pos) + " "
  15. + msg.substring(pos + delim.length());
  16. System.out.println(pos + " iteration result is " + msg);
  17. pos = msg.indexOf(delim);
  18. }
  19. return msg;
  20. }
  21. }
Success #stdin #stdout 0.07s 3359744KB
stdin
Standard input is empty
stdout
Twinkle27
twinkle
little star
7 iteration result is Twinkle twinkle
little star
Twinkle twinkle27
little star
15 iteration result is Twinkle twinkle little star
Twinkle
twinkle
little star
Twinkle twinkle little star