常見JAVA演算法題
阿新 • • 發佈:2019-02-10
publicclass YangHui{
staticvoid yanghui(int a[][],int ROW){
for(int i=0;i<=ROW;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<=ROW;i++){
for(int j=0;j<=a[i].length-1;j++){
System.out.print(a[i][j]+"");
}
System.out.println();
}
}
publicstaticvoid main(String[] args){
finalint ROW=5;
int a[][]=newint[ROW+1][];
for(int i=0;i<= ROW;i++){
a[i]=newint[i+1];
}
yanghui(a,ROW);
}
}
staticvoid yanghui(int a[][],int ROW){
for(int i=0;i<=ROW;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 j=0;j<=a[i].length-1;j++){
System.out.print(a[i][j]+"");
}
System.out.println();
}
}
publicstaticvoid main(String[] args){
finalint ROW=5;
int a[][]=newint[ROW+1][];
for(int i=0;i<=
a[i]=newint[i+1];
}
yanghui(a,ROW);
}
}