« | Home | Recent Comments | Categories | »

Write a program that makes 2 + 2 = 5 – Programming Puzzles & Code Golf

Posted on June 1st, 2014 at 20:42 by John Sinteur in category: Software -- Write a comment

[Quote]:

Write a program that seemingly adds the numbers 2 and 2 and outputs 5. This is an underhanded contest.

import java.lang.reflect.Field;

public class Main {
    public static void main(String[] args) throws Exception {
        Class cache = Integer.class.getDeclaredClasses()[0];
        Field c = cache.getDeclaredField("cache");
        c.setAccessible(true);
        Integer[] array = (Integer[]) c.get(cache);
        array[132] = array[133];

        System.out.printf("%d",2 + 2);
    }
}

previous post: Bowe Bergdahl, American Soldier, Freed by Taliban in Prisoner Trade

next post: A Decade’s Worth of WWDC Keynotes