二维数组

2017-12-27  本文已影响0人  李昱俊
 Scanner scanner = new Scanner(System.in);
            System.out.println("请输入行数");
            int row = scanner.nextInt();

            int[][] array = new int[row][];


            for (int i = 0; i < array.length; i++) {
                array[i] = new int[i + 1];
                array[i][0] = 1;
                array[i][i] = 1;
                if (i > 1) {
                    for (int j = 1; j <= i - 1; j++) {
                        array[i][j] = array[i - 1][j] + array[i - 1][j - 1];

                    }
                }

            }
            for (int x = 0; x < array.length; x++) {
                for (int v = 0; v < array[x].length; v++) {
                    System.out.print(array[x][v] + "     ");
                }
                System.out.println();
            }
上一篇下一篇

猜你喜欢

热点阅读