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 prev = "11";
  13. StringBuilder res = new StringBuilder();
  14. int count = 1;
  15. for(int i=0;i<prev.length();){
  16. int j= i+1;
  17. while(j<prev.length() && prev.charAt(i)==prev.charAt(j)){
  18. j++;
  19. count++;
  20. }
  21. res.append(count + "" + prev.charAt(i));
  22. i=j;
  23. }
  24.  
  25. System.out.println(res.toString());
  26. }
  27. }
Success #stdin #stdout 0.16s 2841600KB
stdin
Standard input is empty
stdout
21