I recently have discovered Click and Hack–the name was inspired by Click and Clack, the hosts of NPR’s Car Talk–who have put together some really interesting Java brain teasers but, unfortunately, do not seem to have a central home page. Here’s a good one I found last night:
Josh: A looper is a loop that’s missing one or two variable declarations. You solve it by coming up with declarations that turn it into an infinite loop. For example, what declaration for i will turn this into an infinite loop:
while (i == -i && i != 0) {
}
Read the article for the answer. Don’t worry if you don’t figure it out; I definitely didn’t get it.
2 responses so far ↓
1 Vikas M R // Aug 17, 2007 at 12:07 am
float i1 = .1f;
while ((int)i1 == (int)-i1 && i1 != 0) {
System.out.println(”XX”);
}
2 Kecsó // Nov 4, 2008 at 8:46 am
public static void main(String[] args){
Integer i = Integer.MIN_VALUE;
if (i == -i && i != 0) {
System.out.println("Clever");
}
}
Leave a Comment