本帖最后由 先小涛 于 2013-4-19 16:43 编辑
- public class Test {
- public static void main(String[] args) {
- showDetail(50);
- }
- public static void showDetail(int startNum, int remainNum,
- StringBuffer result) {
- StringBuffer newReuslt = new StringBuffer(result);
- if (startNum <= remainNum) {
- newReuslt.append(startNum).append("+");
- int newRemainNum = remainNum - startNum;
- if (newRemainNum > startNum) {
- System.out.println(newReuslt.toString() + newRemainNum);
- }
- startNum = startNum + 1;
- showDetail(startNum, newRemainNum, newReuslt);
- for (int i = startNum + 1; i < remainNum / 2; i++) {
- showDetail(i, newRemainNum, new StringBuffer(newReuslt));
- }
- }
- }
- public static void showDetail(int num) {
- for (int i = 1; i < num / 2; i++) {
- System.out.println("以[" + i + "]开始的结果,如下: ");
- showDetail(i, num, new StringBuffer());
- }
- }
- }
复制代码 |