//先把两条边的等值输出,然后再对中间部分进行输出
public class ArrayTest {
public static void main(String[] args) {
int[][] yangHui =new int[10][];
for (int i = 0;i < yangHui.length;i++) {
yangHui[i] = new int[i + 1];
yangHui[i][0] = yangHui[i][i] = 1;
if (i > 1) {
for (int j = 1; j < yangHui[i].length - 1; j++) {
yangHui[i][j] = yangHui[i - 1][j - 1] + yangHui[i - 1][j];
}
}
}
for (int i = 0;i<yangHui.length;i++){
for (int j=0;j<yangHui[i].length;j++){
System.out.print(yangHui[i][j] +"\t");
}
System.out.println();
}
打印杨辉三角
最新推荐文章于 2024-09-03 20:17:53 发布