Sunday, April 19, 2009

Puzzle 16 – Solution

The key to today’s solution is ‘boolean assignment’.

In Java, unlike C/C++ an if statement can only take a boolean condition. However the assignment operator ‘=’ can be used to assign a boolean value inside an if. Thus the statements,
boolean bool;
if (bool = true){
System.out.println(
"Worked!");
}

is legal and evaluates to true inside the if statement.

Congrats to
1. Scott Vachalek
2. Alex R
3. Rama Krishna
4. Anonymous - Sorry but no listing in the leader board for Anonymous entries!

for getting the right answer.

No comments:

Post a Comment

Solution for this question?