Tell me more ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

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.

share|improve this question
oh..... adding more constraints to Java again ;) – Ant's Nov 27 '11 at 7:29
6  
Receive XML as input, output a stacktrace. – Glenn Nelson Nov 27 '11 at 18:12

closed as off topic by dmckee Sep 10 '12 at 23:35

Questions on Programming Puzzles & Code Golf Stack Exchange are expected to relate to programming puzzle or code golf within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

up vote 22 down vote accepted

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.

share|improve this answer
great answer! :) – Ant's Nov 27 '11 at 7:30
I had a similar idea. – Peter Taylor Nov 27 '11 at 7:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.