This brings me to the last puzzle in this series. If you are wondering what I mean – it's just the way I write twisters - A series of 16 puzzles – next week we start with a new set of questions! I like to keep the best for the last and I believe this is the toughest puzzle on twister. Maybe, you don’t – lets get cracking shall we.
package com.twisters;
class DoubleTrouble{
public static void main(String args[])
{System.out.println("This is the wrong one!");}
public static void main(String args[])
{System.out.println("This is the right one!");}
}
Get this to print 'This is the right one!' when the program is run. Oh yes you need to get the code to compile first.
Let’s get to the challenging part shall we.
You cannot change anything about the main() which has the 'This is the wrong one!' print statement. The means no changes allowed to public static void main(String args[]){System.out.println("This is the wrong one!");}
It remains as it is - no changes, no additions, no deletions, no commenting it out - nothing!
Need a hint? One of the puzzles in April holds the solution to this puzzle (Be warned, it’s a complete spoiler). However if you are really stuck, you might want to have a look at the puzzles asked in April!!
Site of the day - http://www.facebook.com/careers/puzzles.php – puzzles on Facebook – isn’t that something we have been waiting for ;)!
Got an answer? Do leave it here.
Here is my solution:
ReplyDeleteclass String {}
class DoubleTrouble{
public static void main(String args[])
{System.out.println("This is the wrong one!");}
public static void main(java.lang.String args[])
{System.out.println("This is the right one!");}
}
By creating a String class, both the String args[] are referring to my String class. To get it to print the proper answer I used a full class name so the proper main() would be called.
class DoubleTrouble {
ReplyDeletepublic static class InnerClass {
public static void main(String args[]) {
System.out.println("This is the wrong one!");
}
}
public static void main(String args[]) {
System.out.println("This is the right one!");
}
}
package com.twisters;
ReplyDeleteclass String{}
class DoubleTrouble{
public static void main(String args[])
{System.out.println("This is the wrong one!");}
public static void main(java.lang.String args[])
{System.out.println("This is the right one!");}
}
class DoubleTrouble{
ReplyDeletestatic class DoubleTrouble1{
public static void main(String args[])
{System.out.println("This is the wrong one!");}
}
public static void main(String args[])
{System.out.println("This is the right one!");}
}
class DoubleTrouble {
ReplyDeletepublic static void main(String args[]) {
System.out.println("This is the wrong one!");
}
public static void main(String args[][]) {
System.out.println("This is the right one!");
}
}
package com.twisters;
ReplyDeleteclass DoubleTrouble {
static class Inner {
public static void main(String args[]) {
System.out.println("This is the wrong one!");
}
}
public static void main(String args[]) {
System.out.println("This is the right one!");
}
}
public class DoubleTrouble {
ReplyDeletestatic class Test {
public static void main(String args[]) {
System.out.println("This is the wrong one!");
}
}
public static void main(String args[]) {
System.out.println("This is the right one!");
}
}
package com.twisters;
ReplyDeleteclass DoubleTrouble{
public static void main(String args[])
{System.out.println("This is the wrong one!");}
public static void main(java.lang.String args[])
{System.out.println("This is the right one!");}
}
class String{}
The main principle here is to fool the program in order for it to believe the "wrong" main is not truly the original main method.
Hi,
ReplyDeleteThis looks pretty cool. Put the main() having "Wrong one" in an inner class like below
package com.twisters;
class DoubleTrouble
{
static class ragha{
public static void main(String args[])
{System.out.println("This is the wrong one!");}
}
public static void main(String args[])
{System.out.println("This is the right one!");}
}
package com.twisters;
ReplyDeleteclass DoubleTrouble{
public static void main(String args[])
{System.out.println("This is the wrong one!");}
static
{
System.out.println("This is the right one!");
System.exit(0);}
}
package com.twisters;
ReplyDeleteclass DoubleTrouble{
public static void main(String args[])
{System.out.println("This is the wrong one!");}
public static void main(java.lang.String args[])
{System.out.println("This is the right one!");}
class String{}
}
package com.twisters;
ReplyDeletepublic class DoubleTrouble{
static class Inner {
public static void main(String args[])
{System.out.println("This is the wrong one!");}
}
public static void main(String args[])
{System.out.println("This is the right one!");}
}
Wrap first main method into innner class.
ReplyDeleteWas thinking on more solutions but cudnt spare much time... leaving this one before sleeping as after that the time will b over ;D
ReplyDeleteclass DoubleTrouble {
public static void main(String args[])
{System.out.println("This is the wrong one!");}
}
public class Trouble {
public static void main(String args[])
{System.out.println("This is the right one!");}
}