A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© ys5214 中级黑马   /  2017-3-23 11:15  /  1050 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

import java.util.Scanner;
public class 杨辉三角 {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                System.out.println("请在下面输入数字");
                int n = sc.nextInt();
                int [][] arr = new int [n][n];
                for(int x = 0;x<n;x++){
                        arr[x][0]=1;
                        arr[x][x]=1;
                }
                for(int x = 2;x<n;x++){
                        for(int y = 1;y<x;y++){
                                arr[x][y]=arr[x-1][y-1]+arr[x-1][y];
                        }
                }
                for(int x = 0;x<n;x++){
                        for(int y = 0;y<=x;y++){
                                System.out.print(arr[x][y]+"\t");
                        }
                                System.out.println();
                }
        }
}
{:8_469:}

3 个回复

倒序浏览
出招吧,少年
回复 使用道具 举报
给个注释啊亲
回复 使用道具 举报
学以致用,太长不看,类名不要定义为中文,你会被项目经理打死。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马