码迷,mamicode.com
首页 > 其他好文 > 详细

使用多重循环打印6阶杨辉三角

时间:2015-04-12 14:49:38      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

public static void main(String[] args) {
int[][] a = new int[6][];
//a[0][0] = 1;
for(int i=0;i<6;i++){
a[i]=new int[i+1];
}
for(int i = 0 ; i < 6 ; i++){
for(int j = 0 ; j <=i ; j++){
if(i == j || j == 0 || i ==0){
a[i][j] = 1;
continue;
}else {
a[i][j] = a[i-1][j-1]+a[i-1][j];
}

}
}
for (int m = 0; m < 6; m++) {
for (int n = 0; n <= m; n++) {
System.out.print(a[m][n]+" ");
}
System.out.print("\n");
}

}

}

使用多重循环打印6阶杨辉三角

标签:

原文地址:http://www.cnblogs.com/yuTseblog/p/4419468.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!