Puzzle (It’s Elementary)
Consider the following example.
package demo;
public class App {
public static void main( String[] args ) {
System.out.println( 12345 + 5432l );
}
}
What do you think the above will print?
17777
This example was taken from PUZZLE 4: IT’S ELEMENTARY in Java™ Puzzlers: Traps, Pitfalls, and Corner Cases.
“Things are seldom what they seem. Take this program, for instance. It doesn’t say what you think it does. Take a careful look at the two operands of the +
operator. We are adding the int
value 12345
to the long
value 5432l
. Note the subtle difference in shape between the digit 1
at the beginning of the left operand and the lowercase letter *el* at the end of the right operand.”