Daniel Pitts said:
I've got mine down to 61 characters. See if you can match that.
Here is a new variant of the above challenge:
Write a java program (source code) with less than 4000
characters and a java command line with less than 1000
characters that writes »Hello World« followed by a newline
character and nothing else, but does so in a somewhat
surprising or unusual way.
My entry:
public class Main
{ public static void main( final java.lang.String[] args )
{ System.out.println(); System.out.print( '\n' ); }}
java -Dline.separator="Hello World" Main
A slightly obfuscated program which illustrates a few surprising things.
public class Hello {
static Object left = "Top", right = "Bottom";
static Object top = "Left";
static Object bottom = "Right";
public static void main(String[] args) throws Exception {
for (int i = 0; i < 2; ++i) {
s.out.print(new Hello());
y(left, right, top, bottom);
}
}
public String toString() {
try {
top = "value";
bottom = "count";
return "enumeration" + top + bottom;
} finally {
return getClass().getName();
}
}
static <T extends java.lang.reflect.AccessibleObject> T t(T t) {
t.setAccessible(true); return t;}
static <T> void y(T l, T r, T... os) throws Exception {
for (Object o : os) {
x(l, o).set(l, x(l, o).get(r));
}
}
private static java.lang.reflect.Field x(Object l, Object o) throws
NoSuchFieldException {
return t(l.getClass().getDeclaredField(o.toString()));
}
{
left = toString();
right = " W" + b + 'r' + a + "d\n";
}
static Object a = "l";
static Object b = "o";
static System s;
}