voidfindContinuousSequence(int s){ if (s < 3) { return; } int small = 1; int big = 2; int mid = (1 + s) / 2; int curSum = small + big;//当前和不从0开始计算 while (small < mid) { if (curSum == s) {//加上small后和是否相等 print(small, big); } while (curSum > s && small < mid) { curSum -= small; small++; if (curSum == s) {//减去small后和是否相等 print(small, big); } } big++; curSum += big; } } voidprint(int small, int big){ StringBuilder s = new StringBuilder(); for (int i = small; i <= big; i++) { s.append(i).append(" "); } System.out.println(s.toString()); }