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 = 0;
  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);
  25. System.out.print('\n');
  26. System.out.print (pos + 1);
  27. }
  28. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
1
11
2
17
3
23
4
30
5
36
6
42
7
48
8
57
9
70
10
78
--final--
10
0