Today’s unearthly puzzle finds its roots in code written by a Jalvanian master. The question in today’s puzzle should be self explanatory.
package com.twister;
public class NoIf {
public static void main(String[] args) {
if(true){}
System.out.println("Print This");
if(true){}
System.out.println("Print This - Not!");
if(true){}
System.out.println("Print This");
}
}
It’s kind of pretty obvious what needs to be done – the code says it all.
You must of course follow the Three Jalvanian Laws.
1. You may only add but not delete nor comment out any of the code.
2. A real Jalvanian would never use an else so neither must you.
3. You may not use any more boolean variables (there are three in the code – which must remain unaltered) or conditions that evaluate to a boolean value. (So no true==false – since false is a boolean value etc).
That’s all folks!!
Got an answer? Do leave it here.
public static void main(String[] args) {
ReplyDeletetry{
if(true){}
System.out.println("Print This");
}catch(Exception e){
if(true){}
System.out.println("Print This - Not!");
}finally{
if(true){}
System.out.println("Print This");
}
}
if(true){}
ReplyDeleteSystem.out.println("Print This");
not:
{
if(true){break not;}
System.out.println("Print This - Not!");
}
if(true){}
System.out.println("Print This");
System.out.println("Print This - Not!".substring(0,10));
ReplyDeletepackage com.twister;
ReplyDeletepublic class NoIf {
public static void main(String[] args) {
if(true){}
System.out.println("Print This");
try
{
if(true){throw new Exception();}
System.out.println("Print This - Not!");
}
catch (Exception e) {
}
if(true){}
System.out.println("Print This");
}
}
package com.twister;
ReplyDeletepublic class NoIf {
public static void main(String[] args) {
if(true){}
System.out.println("Print This");
try
{
if(true){throw new Exception();}
System.out.println("Print This - Not!");
}
catch (Exception e) {
}
if(true){}
System.out.println("Print This");
}
}
package com.twister;
ReplyDeletepublic class NoIf {
public static void main(String[] args) {
if(true){{}
System.out.println("Print This");}
if(!true){{}
System.out.println("Print This - Not!");}
if(true){{}
System.out.println("Print This");}
}
}
package com.twister;
ReplyDeletepublic class NoIf {
public static void main(String[] args) {
if(true){}
System.out.println("Print This");
for(;;){
if(true){break;}
System.out.println("Print This - Not!");
}
if(true){}
System.out.println("Print This");
}
}
package com.twister;
ReplyDeletepublic class NoIf {
public static void main(String[] args) {
if(true){}
System.out.println("Print This");
try {
if(true){throw new RuntimeException()}
System.out.println("Print This - Not!");
} catch (RuntimeException e) {}
if(true){}
System.out.println("Print This");
}
}
package com.twister;
ReplyDeletepublic class NoIf {
public static void main(String[] args) {
if(true){}
System.out.println("Print This");
if(true){}
try {}
catch(Exception e) {
System.out.println("Print This - Not!");
}
if(true){}
System.out.println("Print This");
}
}
redirect the System.out before the second println with
ReplyDeleteSystem.setOut() and undo it before the third