java进行金字塔形数组输出

我想实现一个从控制台读取行数,然后进行循环输出的金字塔的代码
输出的结果如下所示:
00000001
000000212
0000032123
00004321234
000543212345
0065432123456
07654321234567
零为防止缩进了我的空格

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        for(int i=0;i<a;i++){
            for(int j=-a+1;j<=a-1;j++){
                if(Math.abs(j)>i)
                    System.out.print(" ");
                else
                    System.out.print(Math.abs(j)+1);
            }
            System.out.print("\n");
        }
    }

使用双重循环,第一层控制行数(由控制台输入);第二层有两个for循环,第一个for循环控制空格,第二个for循环控制输入内容

System.out.println("请输入需要打印的金字塔数行数:");
        Scanner scan = new Scanner(System.in);
        int lineNum = scan.nextInt();
        int len = lineNum * 2 - 1; // 计算最后一行的数字长度
        char[] outChar = new char[len]; // 构造一个char数组来存储输出的内容,有数字放数字,没有的用空格代替
        for (int i = 0; i < outChar.length; i++) { // 先设置成全部空格
            outChar[i] = ' ';
        }
        for (int i = 0; i < lineNum; i++) { // 控制输出的行数
            outChar[len/2+i] = (char) (i+49);   //49表示的数字1
            outChar[len/2-i] = (char) (i+49);
            System.out.println(new String(outChar));
        }```