Pacific-Design.com

    
Home Index

1. Algorithms

2. Find Smallest Difference

Algorithms / Find Smallest Difference /

Find the smallest difference absolute difference between two numbers

public int SmalestDifference(int[] array){

      int min = 0;
      Arrays.sort(array);

      for(int i = 1; i  <  (array.length - 1); i++){

         int temp = Math.abs(array[i+1] - array[i]);
         if (temp <= min) min = temp;
      }

      return min;
  }