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.
Main idea to place output statement to if clause:
ReplyDeletepublic static void main(String[] args) {
if (System.out.append("Hello world") != null) {}
}
Main idea to place output statement to if clause:
ReplyDeletepublic static void main(String[] args) {
if (System.out.append("Hello world") != null) {}
}
public static void main(String[] args) {
ReplyDeleteif (System.out.printf("%s\n", "Hello World") != null) {}
}
public class Twister { public static void main(String[] args){while(System.out.printf("Hello World", null) == null){}}}
ReplyDeletePosting 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
ReplyDeleteif(System.out.printf("Hello World!")==null){}
ReplyDeleteHere is it
ReplyDeletepublic 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) {
}
}
}
I have another one:
ReplyDeletestarts 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 :-)
One more solution (for java from 1.5)
ReplyDeleteif (System.out.printf("Hello, World!!!") != null) {}