class X{
public static void main(String[] a){
System.out.print(a[0]);
}
}
Run the program as given below
java X "Hello World"
The second one – (the one that I had in mind) is
class X {
static {
System.out.print("Hello World");
System.exit(0);
}
}
Java Coding with a difference!
class X{
public static void main(String[] a){
System.out.print(a[0]);
}
}
Run the program as given below
java X "Hello World"
class X {
static {
System.out.print("Hello World");
System.exit(0);
}
}
“Twisters is a coding competition with a difference.
It requires that you write a very simple Code. Most of the programs are not more than 20 lines!!!
E.g.: Write a Code to add two integers :-).
Twist – Do not use the plus sign in the entire program!!
A simple solution is,
{
int a = 10; b = 40;
int sum;
sum = a – (-b);
}”
Over the years there I have come across few tricks and tips in Java that also puts you off track. Here I present a collection of all such puzzles.
2 comments:
Run class without main method?
Yes - Technically i would say running a java class is basically passing a 'java class' as parameter to the java program! The java program does what it does best namely call the static main method of the program. So yes while wired its still possible to run a class without main! At least that's the way I see it.
Cheers - Sam
Post a Comment
Solution for this question?