效果图

QQ截图20190425151338.jpg

public class yanghui
{
    public static void main(String[] args)
    {
        int row = 8;// 定义行数
        int[][] arr = new int[row][row];
        // 双循环操作数组 并且给数组赋值
        for (int i = 0; i < row; i++) 
        {
            for (int j = 0; j <= i; j++)
            {
                if(i != 0 && j != 0)
                {
                    arr[i][j] = arr[i - 1][j] + arr[i - 1][j - 1];
                }
                else if(i != 0)
                {
                    arr[i][j] = arr[i - 1][j];
                }
                else
                {
                    arr[i][j] = 1;
                }
            }
        }
        // 打印数组
        for (int i = 0; i < row; i++) 
        {
            for (int j = 0; j <= i; j++) 
            {
                System.out.print(arr[i][j]+" ");
            }
            System.out.println();
        }
    }
}