2013-07-01
展开全部
package com.javabean;
public class YangHui {
public static void main(String args[]) {
int r = 5;
int a[][] = new int[r + 1][];
for (int i = 0; i <= r; i++) {
a[i] = new int[i + 1];
}
yanghui(a, r);
}
static void yanghui(int a[][], int r) {
for (int i = 0; i <= r; i++)
for (int j = 0; j <= a[i].length - 1; j++) {
if (i == 0 || j == 0 || j == a[i].length - 1)
a[i][j] = 1;
else
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
}
for (int i = 0; i <= r; i++) {
for (int j = 0; j <= a[i].length - 1; j++)
System.out.print(a[i][j] + " ");
System.out.println();
}
}
}
public class YangHui {
public static void main(String args[]) {
int r = 5;
int a[][] = new int[r + 1][];
for (int i = 0; i <= r; i++) {
a[i] = new int[i + 1];
}
yanghui(a, r);
}
static void yanghui(int a[][], int r) {
for (int i = 0; i <= r; i++)
for (int j = 0; j <= a[i].length - 1; j++) {
if (i == 0 || j == 0 || j == a[i].length - 1)
a[i][j] = 1;
else
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
}
for (int i = 0; i <= r; i++) {
for (int j = 0; j <= a[i].length - 1; j++)
System.out.print(a[i][j] + " ");
System.out.println();
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询