Sunday, November 1, 2009

Puzzle 57 – Hello World - Again

Language – Java | Type – Concept | Last date 8-Nov-2009 12:00 p.m. IST | Points 3

It's been two weeks since I wrote a puzzle out here – so I end up typing the simplest program I could think of in Java.

class X{
public static void main(String[] a){
System.out.print(
"Hello World");
}
}

That's the smallest program that I could in java that prints hello world (72 characters excluding all the white spaces). Hope you folks noticed the clever use of variable names and print instead of println.

Well here is the really simple challenge. Write some code that does exactly what the above code does – just use less number of characters. Remember the code has got to compile cleanly and run cleanly and produce the same output as the snippet above. Easy!

Looking for more Java Puzzles? Check out these sites.

Got an answer? Leave one here.

4 comments:

  1. class X{
    public static void main(String[] a){
    System.out.print(a[0]);
    }
    }

    Run the program as given below
    java X "Hello World"

    ReplyDelete
  2. 62 characters:

    class X {
    static {
    System.out.print("Hello World");
    System.exit(0);
    }
    }

    ReplyDelete
  3. class X{
    public static void main(String[] a){
    System.out.print(a[0]);
    }
    }

    $ javac X.java
    $ java X "Hello World"

    ReplyDelete
  4. class X{
    public static void main(String[] a)
    {
    System.out.print(a[0]);
    }
    }

    pass "Hello world" as argument

    ReplyDelete

Solution for this question?