为什么这里的combArray是空的而下面
这里明明给combArray赋值了呀
源代码如下:
import java.util.ArrayList;
import java.util.List;
public class FindCombination {
private int begin, end;// 组合最小、大长度
// number长度的组合集合
private List combArray = new ArrayList();
// begin-end长度的组合集合
private List combBalls = new ArrayList();
public FindCombination(CombNode[] array, int begin, int end) {//初始器
this.begin = begin;
this.end = end;
if (array == null || array.length == 0 || begin > end) {
System.out
.println("wrong,the reason maybe is :\"array==null\" or \"array.length == 0\" or \"begin>end\"");
return;
}
List list = new ArrayList();
for (int length = begin; length end) {
System.out
.println("wrong,the length must be greater than begin and less than end at the same time");
return null;
}
return combBalls.get(length);
}
public void printCombination() {// 打印所有组合
for (int i = 0; i < combBalls.size(); i++) {
for (int j = 0; j < combBalls.get(i).size(); j++) {
System.out.print(combBalls.get(i).get(j).getValue() + " ");
}
System.out.println();
}
}
public static void main(String[] args) {
String[] array = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
// int[] array={1,2,3,4,5,6,7,8,9,10};
CombNode[] cn = new CombNode[10];
for (int i = 0; i < array.length; i++) {
cn = new CombNode(array, true);
}
System.out.println("\n***********");
FindCombination fc = new FindCombination(cn, 1, 2);
System.out.println("***********");
System.out.println("通过方法打印");
fc.printCombination();
}
} |