import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class RecurTable {
public static void main(String[] args) {
printTable(9);
}
static void printTable(int maxLine) {
for (int i = 1; i <= maxLine; i++) {
System.out.println(getLine(i));
}
}
static List<Integer> getLine(int lineNumber) {
List<Integer> list;
if (lineNumber == 1) {
list = new ArrayList<>();
list.add(1);
return list;
} else {
list = getLine(lineNumber - 1);
for (int i = 0; i < list.size(); i++) {
list.set(i, list.get(i) + i + 1); //下一行中每一列都对应加列号
}
list.add(list.get(list.size() - 1) + lineNumber);
}
return list;
}
}
运行效果图: