Fare丶梦


私信TA

用户名:126913199

访问量:31331

签 名:

等  级
排  名 141
经  验 4928
参赛次数 0
文章发表 50
年  龄 22
在职情况 学生
学  校
专  业

  自我简介:

解题思路:





注意事项:

格式错误(仅供参考)



参考代码:

import java.util.Scanner;


public class Main {

        public static void main(String[] arg){

                @SuppressWarnings("resource")

                Scanner sc = new Scanner(System.in);

                int N = sc.nextInt();

                N = N + 1;

                int[][] array = new int[N][N];

                for(int i = 0;i<array.length;i++){

                        for(int k=N;k>0;k--){

                                System.out.print("   ");

                        }

                        for(int j=0;j<=i;j++){

                                array[i][j] = 0;

                                if(j==0||j==i){

                                        array[i][j]=1;

                                }

                                else

                                        array[i][j]=array[i-1][j]+array[i-1][j-1];

                                if(i!=j){

                                        System.out.print(array[i][j]+"     ");

                                        }

                                else

                                        System.out.print(array[i][j]+"  ");

                        }

                        N--;

                        System.out.println();

                }

        }

}


 

0.0分

0 人评分

  评论区