Sunday, July 12, 2009

Puzzle 41 – Hello World

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

Lately I have been reading up on groovy and the hello world program in groovy is just so groovy!

println ‘Hello World’

This brings me to the next questions!

Write a program that prints Hello World in Java. No Semicolons anywhere in the code. No, not even one!! Not even using a alternate notation like unicode!!

P.S – I know Groovy can be run as a Java program – but here I mean Java code, that compiles using the javac compiler!!

Got an answer? Do leave it here.

9 comments:

  1. Main idea to place output statement to if clause:

    public static void main(String[] args) {
    if (System.out.append("Hello world") != null) {}
    }

    ReplyDelete
  2. Main idea to place output statement to if clause:

    public static void main(String[] args) {
    if (System.out.append("Hello world") != null) {}
    }

    ReplyDelete
  3. public static void main(String[] args) {

    if (System.out.printf("%s\n", "Hello World") != null) {}

    }

    ReplyDelete
  4. public class Twister { public static void main(String[] args){while(System.out.printf("Hello World", null) == null){}}}

    ReplyDelete
  5. Posting comments here has become quite a twister, too. The word verification is not displayed initially, as well as the input field and button. I need to tab to the invisible button in order to submit a comment. This is on FF3.5

    ReplyDelete
  6. if(System.out.printf("Hello World!")==null){}

    ReplyDelete
  7. Here is it

    public class GroovyStyle {

    public static void main(String[] args) throws Exception {
    if(java.io.PrintStream.class.getMethod("println", String.class).invoke(System.out, "Hello, world!!!") == null) {

    }
    }
    }

    ReplyDelete
  8. I have another one:
    starts below this line:
    and ends above this line.

    Yes, it's the nonexistent java program.
    Run it as follows:

    java Hello\ World

    and it will print "Hello World" and some other "garbage":

    hobel[~]: java Hello\ World
    Exception in thread "main" java.lang.NoClassDefFoundError: Hello World
    Caused by: java.lang.ClassNotFoundException: Hello World
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: Hello World. Program will exit.

    If you really want to have code to complie for javac try this:
    public class A{} and then run it as shown above :-)

    ReplyDelete
  9. One more solution (for java from 1.5)
    if (System.out.printf("Hello, World!!!") != null) {}

    ReplyDelete

Solution for this question?