public static boolean sum2(int ary[], int sum) { int start = 0; int end = ary.length - 1; for (; start < end; ) { if (ary[start] + ary[end] == sum) { return true; } else if (ary[start] + ary[end] > sum) {//大于时,end左移动 end--; } else {//小于的情况 start++; } } return false; }