fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import static java.lang.System.out;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main(String[] a) {
  9. out.println(c("Hello, this is [?] world!"));
  10. out.println(c("How about we build [?] big building. It will have [?] orange banana hanging out of [?] window."));
  11. out.println(c("[?] giant en le sky."));
  12. out.println(c("[?] yarn ball? [?] big one!"));
  13. out.println(c("[?] hour ago I met [?] European. "));
  14. out.println(c("Hey sir [Richard], how 'bout [?] cat?"));
  15. out.println(c("[?] dog is barking. [?] cat is scared!"));
  16. }
  17.  
  18. static String c(String s) {
  19. String x[] = s.split("\\[\\?\\]", 2), r = x[0];
  20. if (x.length > 1)
  21. return r + (r.matches("(.+[.!?] )|(^)$")?"A":"a")
  22. + ("aeiouAEIOU".contains("" + x[1].charAt(1)) ? "n" : "") + c(x[1]);
  23. else
  24. return r;
  25. }
  26. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
Hello, this is a world!
How about we build a big building. It will have an orange banana hanging out of a window.
A giant en le sky.
A yarn ball? A big one!
A hour ago I met an European. 
Hey sir [Richard], how 'bout a cat?
A dog is barking. A cat is scared!