Wednesday, April 29, 2009

Puzzle 19 - Solution

If you are a Java programmer the only solution that I know of is to use ‘recursion’.
So you would have code
class Infinite{
public static void infinite(){
System.out.println(
1);
infinite();
}
public static void main(String args[]){
infinite();
}
}

If you are a C/C++ programmer there is one more way to generate a true infinite loop using the infamous ‘Goto’. So you can code

public static void infinite(){
cout<<1;
infinite();
}
public static void main(int argc char * argv[]){
infinite();
}
Congrats to
1. Bernardomen
2. Chanti
3. Joe Smith
for getting the answer right.

No comments:

Post a Comment

Solution for this question?