import java.util.ArrayList; import java.util.Iterator; public class FunnyIntegerSet { private ArrayList a = new ArrayList(); public void insert(int x) { a.add(new Integer(x)); } /* This code is WRONG */ public int findClosest(int x) { Iterator it = a.iterator(); int closest = (Integer)it.next(); while(it.hasNext()) { int value = (Integer)it.next(); if (Math.abs(value - x) < closest - x) closest = value; } return closest; } }