Popular Posts

Wednesday, September 21, 2011

Java Puzzles: loopy puzzlers


class BigDelight {
    public static void main(String[] args) {
        for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) {
            if (b == 0x90)
                System.out.print("Joy!");
        }
    }
}


public class Increment {
    public static void main(String[] args) {
        int j = 0;
        for (int i = 0; i < 100; i++)
            j = j++;
        System.out.println(j);
    }
}


public class InTheLoop {
    public static final int END = Integer.MAX_VALUE;
    public static final int START = END - 100;

    public static void main(String[] args) {
        int count = 0;
        for (int i = START; i <= END; i++)
            count++;
        System.out.println(count);
    }
}


public class Shifty {
    public static void main(String[] args) {
        int i = 0;
        while (-1 << i != 0)
            i++;
        System.out.println(i);
    }
}


public class Looper {
    public static void main(String[] args) {
        // Place your declaration for i here

        while (i == i + 1) { 
        }
    }
}


public class BrideOfLooper {
    public static void main(String[] args) {
        // Place your declaration for i here

        while (i != i) { 
        }
    }
}


public class SonOfLooper {
    public static void main(String[] args) {
        // Place your declaration for i here

        while (i != i + 0) { 
        }
    }
}


public class GhostOfLooper {
    public static void main(String[] args) {
        // Place your declaration for i here

        while (i != 0)
            i >>>= 1;
    }
}


public class CurseOfLooper {
    public static void main(String[] args) {
        // Place your declarations for i and j here

        while (i <= j && j <= i && i != j) {
        }
    }
}


public class LooperMeetsWolfman {
    public static void main(String[] args) {
        // Place your declaration for i here

        while (i != 0 && i == -i) {
        }
    }
}


public class Count {
    public static void main(String[] args) {
        final int START = 2000000000;
        int count = 0;
        for (float f = START; f < START + 50; f++)
            count++;
        System.out.println(count);
    }
}


public class Clock {
    public static void main(String[] args) {
        int minutes = 0;
        for (int ms = 0; ms < 60*60*1000; ms++)
            if (ms % 60*1000 == 0)
                minutes++;
        System.out.println(minutes);
    }
}


No comments: