【程序33】
题目:打印出杨辉三角形(要求打印出10行如下图)
1.程序分析:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
public class Ex33 {
public static void main(String args[]){
int i,j;
int a[][];
a=new int[8][8];
for(i=0;i<8;i++){
a[i][i]=1;
a[i][0]=1;
}
for(i=2;i<8;i++){
for(j=1;j<=i-1;j++){
a[i][j]=a[i-1][j-1]+a[i-1][j];
}
}
for(i=0;i<8;i++){
for(j=0;j
System.out.printf(" "+a[i][j]);
}
System.out.println();
}
}
}
【程序34】题目:输入3个数a,b,c,按大小顺序输出。
1.程序分析:利用指针方法。
public class Ex34 {
public static void main(String[] args){
int []arrays = {800,56,500};
for(int i=arrays.length;--i>=0;){
for(int j=0;j
if(arrays[j]>arrays[j+1]){
int temp=arrays[j];
arrays[j]=arrays[j+1];
arrays[j+1]=temp;
}
}
}
for(int n=0;n
System.out.println(arrays[n]);
}
}