fork(5) 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. static String solution(String S) {
  11. if (S.length() < 2) return "meh";
  12. S = S.replaceAll(" |-", "");
  13. StringBuffer result = new StringBuffer();
  14. for (int i = 0; i < S.length(); i++) {
  15. result.append(S.charAt(i));
  16. if (i >= 2 && (i+1)%3 == 0) {
  17. result.append('-');
  18. }
  19. }
  20. return result.toString();
  21. }
  22.  
  23. public static void main (String[] args) throws java.lang.Exception
  24. {
  25. System.out.println(solution("00-44 48 5555 8361"));
  26. }
  27. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
004-448-555-583-61