Jul 21, 2009

Small Answer for Small java pzzule!

/* What declaration turns this loop into infinitive loop.*/

public class GhostOfLooper {

public static void main(String[] args) {

// Place your declaration for i here

while (i != 0)

i >>>= 1;

}

}

Solution:

// Place your declaration for i here

byte i = -1;

Solution for java puzzles(3)

/*What declaration turns this loop into infinitive loop.*/

public class Looper {
public static void main(String[] args) {
// Place your declaration for i here

while (i == i + 1) {
}
}
}

Solution:
// Place your declaration for i here
double i = 1.0/0.0

Solution for java puzzles(2)!

/*Provide declarations for the variables x and i such that*/

public class Tweedledum {
public static void main(String[] args) {
// Put your declarations for x and i here
x += i; // Must be LEGAL
x = x + i; // Must be ILLEGAL
}
}
solution:
// Put your declarations for x and i here
int x=0;
byte i;

Solution for Java puzzles(1).

/*Provide a declaration for Enigma that makes the program print false.*/

public class TestClass{
public static void main(String[] args) {
Enigma e = new Enigma();
System.out.println(e.equals(e));
}
}

final class Enigma {
// Provide body that makes TestClass print false.
// Do n't override equals method in object class.
}
:Solution
final class Enigma {
public Enigma(){
System.out.print("false");
System.exit(0);
}
}
Any other solution will be appreciated ...