import java.util.Arrays; public class Test { public static int[] run(int[] input){ if(input == null || input.length <=1){ return input; } //排序 int temp = 0; for(int i= input.length-1;i>=1;i--){ for(int j= 0;j<=i-1;j++){> input[j+1]){ temp = input[j]; input[j] = input[j+1]; input[j+1] = temp; } } } //算差值 int index =0,min=Integer.MAX_VALUE; for(int i= 0;i<=input.length-2;i++){ if(input[i+1]-input[i]<=min){ index = i; min = input[i+1]-input[i]; } } return Arrays.copyOfRange(input, index, index+2); } public static void main(String[] args) { int[] input =new int[]{161,189,167,172,188}; int[] output = run(Arrays.copyOf(input, input.length)); for(int i :output){ System.out.println(i); } } } 来源:<http://www.oschina.net/question/1422726_163137>