fork(1) 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[] a) {
  11. System.out.println(c("Hello, this is [?] world!"));
  12. System.out.println(c("How about we build [?] big building. It will have [?] orange banana hanging out of [?] window."));
  13. System.out.println(c("[?] giant en le sky."));
  14. System.out.println(c("[?] yarn ball? [?] big one!"));
  15. System.out.println(c("[?] hour ago I met [?] European. "));
  16. System.out.println(c("Hey sir [Richard], how 'bout [?] cat?"));
  17. System.out.println(c("[?] dog is barking. [?] cat is scared!"));
  18. }
  19.  
  20. static String c(String s) {
  21. String x[] = s.split("\\[\\?\\]", 2), r = x[0];
  22. return x.length > 1 ? r + (r.matches("(.+[.!?] )|(^)$") ? "A" : "a")
  23. + ("aeiouAEIOU".contains("" + x[1].charAt(1)) ? "n" : "") + c(x[1]) : r;
  24. }
  25. }
Success #stdin #stdout 0.04s 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!