递归打印即可,第一层打印n个,第二层打印n-1个,直到打印结束。

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            print(1,n,0);
        }
    }
    public static void print(int start,int n,int c){
        int temp = start;
        if(n==0)return;
        else for(int i =0;i<n;++i){
            System.out.print(start+i+" ");
            start = start+i+1+c;
        }
        System.out.println();
        print(temp+1+c,n-1,c+1);
    }
}