fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. String test1 = "50 min";
  10. String test2 = "20 hrs 50 mins";
  11. String test3 = "1 d 20 hrs 50 min";
  12. String test4 = "3 meses 15 dias 20 horas 50 minutos";
  13.  
  14. System.out.println(format(test1));
  15. System.out.println(format(test2));
  16. System.out.println(format(test3));
  17. System.out.println(format(test4));
  18. }
  19.  
  20. private static String format(String string){
  21. Scanner scanner = new Scanner(string);
  22. StringBuilder sb = new StringBuilder();
  23. while(scanner.hasNext()){
  24. sb.append(scanner.next())
  25. .append(scanner.next())
  26. .append(" ");
  27. }
  28. return sb.toString();
  29. }
  30. }
Success #stdin #stdout 0.16s 321344KB
stdin
Standard input is empty
stdout
50min 
20hrs 50mins 
1d 20hrs 50min 
3meses 15dias 20horas 50minutos