本帖最后由 Capricious 于 2017-2-7 00:14 编辑
public static void main(String[] args) {
ArrayList<int[]> list = new ArrayList<>();
list.add(new int[]{1});
for (int i = 1; i < 10; i++) { //i 是集合的索引
int[] arr = new int[i+1];
arr[0] = 1;
for(int j = 1; j < i; j++){ //j是数组的索引
arr[j] = list.get(i-1)[j]+list.get(i-1)[j-1];
}
arr= 1; //这里是arr = 1;
list.add(arr);
}
String str = "";
for(int[] i : list){
for(int j : i){
if(j<10)
str = " "+j;
else if (j<100)
str = " "+j;
System.out.print(str+" ");
}
System.out.println();
}
} |