Popular Posts

Wednesday, September 21, 2011

Java Puzzles


Puzzle# 1:
public class Oddity {
    public static boolean isOdd(int i) {
        return i % 2 == 1;
    }

    public static void main(String[] args) {

    }
}


Puzzle# 2:
public class Change {
    public static void main(String args[]) {
        System.out.println(2.00 - 1.10);
    }
}


Puzzle# 3:
public class LongDivision {
    public static void main(String[] args) {
        final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000;
        final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000;

        System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY);
    }
}


For more exciting puzzles and descriptive insight please see Java Puzzler book by Joshua Bloch and Neal Gafter

No comments: