一点小的回答!
我想到的也是最后这个办法,不过这个方法近似于穷举,要知道所有的情况才能这样做,不知道所有的情况就没办法了。
回复 10# 的帖子
运行时候结果为空!
么原因啊?
程序代码:package wwwww;
public class Untitled1 {
static int sum = 0;
static int count = 0;
public static void main(String[] args) {
final int result = 10;
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
for (int i = 0; i < a.length; i++) {
for (int j = 1; j < a.length; j++) {
if ((a[i] + a[j]) == result) {
if (a[i] != a[j]) {
if (a[i] < a[j]) {
System.out.println("result=" + a[i] + "+" + a[j]);
}
}
}
for (int m = 2; m < a.length; m++) {
if ((a[i] + a[j] + a[m]) == result) {
if (a[i] < a[j]) {
if (a[j] < a[m]) {
if (a[i] != a[j]) {
if (a[i] != a[m]) {
if (a[j] != a[m]) {
System.out.println("result=" + a[i] +
"+" +
a[j] + "+" +
a[m]);
}
}
}
}
}
}
for (int n = 3; n < a.length; n++) {
if ((a[i] + a[j] + a[m] + a[n]) == result) {
System.out.println("result=" + a[i] +
"+" + a[j] +
"+" + a[m] +
"+" + a[n]);
}
}
}
}
}
}
}

