Write a code golf problem in which Java wins

19

2

Write a code golf task such that

  1. The only input (if any) required by the task is text from standard input, and the only output required by the task is text to standard output.
  2. There is exactly one correct output string of characters for every possible legal input as defined by the task.
  3. Each possible legal input is less than 10000 characters long.
  4. Each correct output is less than 10000 characters long.
  5. The shortest program (that StackExchange users manage to write) that successfully completes the task for every input is in Java.

The task with the shortest associated Java program wins.

JohnJamesSmith

Posted 2011-11-26T21:47:35.433

Reputation: 319

Question was closed 2012-09-10T23:35:32.690

oh..... adding more constraints to Java again ;) – Ant's – 2011-11-27T07:29:50.287

9Receive XML as input, output a stacktrace. – Glenn Nelson – 2011-11-27T18:12:07.453

Answers

31

48 characters

Task: Ignore any input. Always produce exactly the following output:

java.lang.ExceptionInInitializerError
Caused by: java.lang.ArithmeticException: / by zero
    at M.<init>(M.java:1)
    at M.<clinit>(M.java:1)

Solution:

enum M{M;System x;{x.setErr(x.out);int y=1/0;}}

Save as M.java, compile with javac M.java and run with java M. It also produces an error message on standard error, but that doesn't violate any of the rules.

hammar

Posted 2011-11-26T21:47:35.433

Reputation: 4 011

I had a similar idea. – Peter Taylor – 2011-11-27T07:53:13.170