杨辉三角
作者:互联网
package com.oop.demo01;
public class yanghui {
public static void main(String[] args) {
int[][] yanghui=new int[12][];
for (int i = 0; i <yanghui.length ; i++) {
yanghui[i] = new int[i + 1];//给一个一维数组增加新空间
for (int j = 0; j <yanghui[i].length ; j++) {
if(j == 0 || j==yanghui[i].length-1){
yanghui[i][j]=1;
}else{
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();
}
}
}
标签:int,System,yanghui,杨辉三角,new,public,out 来源: https://www.cnblogs.com/woziji/p/15423876.html