日期:2014-05-20 浏览次数:20734 次
public class AddNum { public static void main(String args[]) { int num = 99; int mid = num / 2 + 1; int sum = 0; int start, end; for (int i = 0; i < mid + 1; i++) { start = i; for (int j = i + 1; j < mid + 1; j++) { sum = sum + j; if (sum == num) { end = j; System.out.println(start + 1 + "-----" + end); } } sum = 0; } } }
------解决方案--------------------