实验四
程序代码:
package yanghui;
public class YH {
public static void main(String[]args) {
int i=1;
int yh[]=new int[8];
for(i=0;i<5;i++) {
yh[i]=1;
for(int j=i-1;j>0;j--) {
yh[j]=yh[j-1]+yh[j];
}
for(int j=0;j<=i;j++) {
System.out.print(yh[j]+"\t");
}
System.out.println();
}
}
}
实验结果:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
心得:
这次实验中用到了一维数组,还有很多个for循环,其中for循环中的嵌套循环要格外仔细,否则会搞混大括号的匹配以及循环顺序。对于JAVA程序的编写还不够熟练,要多加练习。