fork 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 payload = "501myName\r\n5021\r\n5031\r\n50555\r\n5040\r\n5061\r\n5070\r\n508text\r\n509moretext\r\n511900\r\n";
  13. int cnt = 1;
  14. int pos = 0;
  15. while((pos = payload.indexOf('\n', pos)) != -1){
  16. cnt++;
  17. pos++;
  18. System.out.print (cnt);
  19. System.out.print('\n');
  20. System.out.print (pos);
  21. System.out.print('\n');
  22. }
  23. System.out.print("--final--\n");
  24. System.out.print (cnt + 1);
  25. System.out.print('\n');
  26. System.out.print (pos);
  27. }
  28. }
Success #stdin #stdout 0.07s 3359744KB
stdin
Standard input is empty
stdout
2
11
3
17
4
23
5
30
6
36
7
42
8
48
9
57
10
70
11
78
--final--
12
-1