æç
§ä½ çè¦æ±ç¼åçJavaç¨åºå¦ä¸:
public class D {
public static void main(String[] args) {
int levelcount =5;
int [][]yanghui= new int[levelcount][0];
for(int i=0;i < levelcount;i++){
yanghui[i]=new int[i+1];
for(int j=0;j<=i;j++){
if(i==0){
yanghui[i][j]=1;
}else{
int value=0;
if(j>=1){
value+=yanghui[i-1][j-1];
}
if(j<i){
value+=yanghui[i-1][j];
}
yanghui[i][j]=value;
}
}
}
for(int i=0;i<levelcount;i++){
for(int j=0;j<levelcount-i;j++){
System.out.print (" ");
}
for(int j=0;j<=i;j++){
if(j==i)
System.out.print(yanghui[i][j]);
else
System.out.print(yanghui[i][j]+"-");
}
System.out.println();
}
}
}
è¿è¡ç»æ:
1
1-1
1-2-1
1-3-3-1
1-4-6-4-1