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 initial = "djsndni123412ndksnd3412*&^%34(*(*1234";
  13. // remove all non-digits characters
  14. String processed = initial.replaceAll("\\D", "");
  15. StringBuilder sb = new StringBuilder(processed);
  16. System.out.println(sb);
  17. int gap = 0;
  18. for (int i = 4; i< sb.length()-1;i+=4){
  19. sb.insert(i + gap,' ');
  20. gap++;
  21. }
  22. System.out.println(sb);
  23. }
  24. }
Success #stdin #stdout 0.07s 27780KB
stdin
Standard input is empty
stdout
1234123412341234
1234 1234 1234 1234