fork(9) 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 final String compact(String value) {
  11. return value.replaceAll(".?\\*+.?", "");
  12. }
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. String[] data = {
  16. "ab*cd",
  17. "ab**cd",
  18. "a****",
  19. "ab****",
  20. "*****",
  21. "abc**",
  22. "abc*"
  23. };
  24. for (String s : data) {
  25. System.out.printf("Replace %15s to '%s'\n", s, compact(s));
  26. }
  27. // your code goes here
  28. }
  29. }
Success #stdin #stdout 0.11s 320256KB
stdin
Standard input is empty
stdout
Replace           ab*cd to 'ad'
Replace          ab**cd to 'ad'
Replace           a**** to ''
Replace          ab**** to 'a'
Replace           ***** to ''
Replace           abc** to 'ab'
Replace            abc* to 'ab'