1、纯for循环
for (int i = 0; i < arr.length; i++) { for (int j = i + 1; j < arr.length; j++) { if (arr[i] + arr[j] == 100) { System.out.println(arr[i] + ":" + arr[j]); } } }
2、卡住一个端,左端只有小于M/2才会判断
for (int i = 0; i < arr.length; i++) { if (arr[i] <= 100 / 2) { for (int j = i + 1; j < arr.length; j++) { if (arr[i] + arr[j] == 100) { System.out.println(arr[i] + ":" + arr[j]); } } } }
3、卡住一个端,左端只有小于M/2,右端大于M/2才会判断
for (int i = 0; i < arr.length; i++) { if (arr[i] <= 100 / 2) { for (int j = i + 1; j < arr.length; j++) { if (arr[j] >= 100 / 2) { if (arr[i] + arr[j] == 100) { System.out.println(arr[i] + ":" + arr[j]); } } } } }