private static int findClosest(int desiredFactor,Set<Integer> factors){
  int bestFactor=1;
  int bestDelta=desiredFactor;
  for (  Integer factor : factors) {
    int testDelta=Math.abs(desiredFactor - factor);
    if (testDelta < bestDelta) {
      bestDelta=testDelta;
      bestFactor=factor;
    }
  }
  return bestFactor;
}

private static int findClosest ( int desiredFactor , Set < Integer > factors ) { int bestFactor = 1 ; int bestDelta = desiredFactor ; for ( Integer factor : factors ) { int testDelta = Math . abs ( desiredFactor - factor ) ; if ( testDelta < bestDelta ) { bestDelta = testDelta ; bestFactor = factor ; } } return bestFactor ; }
finds the factor that is closest to the desired factor , from an ordered list of factors .
