| 这道题也是我那天在学习的过程中无意看到的,想了很久没有想出来,但是后来在网上查了很久终于在一个朋友那里看见了他的这个程序,我觉得思路还蛮清晰的,希望对你有帮助! package cn.dan.wenti ;
 public class Test {
 public static void function(int[] str, int n, int m) {
 if (n == 0) {
 for (int i = 0; i <= m - 1; i++) {
 if (i == (m - 1))
 System.out.println(str[i]);
 else
 System.out.print(str[i] + " ");
 }
 } else {
 for (int i = n; i >= 1; i--) {
 if (m == 0 || i <= str[m - 1]) {
 str[m] = i;
 function(str, n - i, m + 1);
 }
 }
 }
 }
 
 public static void main(String[] args) {
 function(new int[6], 6, 0);
 }
 }
 
 |