求高手帮忙解决用一维数组输出杨辉三角
我的程序在此
帮忙改正谢谢
public class QString {
public static void main(String[] args){
int j = 0;
int i = 0;
for(i = 1 ; i < 9 ; i++){
int []b = new int [i];
for(j = 0 ; j <= i; j++){
if(j < 2||(j == 0||j == i)){
b[j] = 1;
}
b[j] = b[j] + b[j-1];
}

for(int v : b){
System.out.println(v +" ");
}
}
}}

解决方案 »

  1.   

    public static void main(String args[]) {        int i = 1;
            int k = 1;
            int j = 10;// 控制打印的行数
            int count[] = new int[11];// 新排的数据
            int count1[] = new int[11];// 用来装住新排的数据
            for (k = 1; k <= j; k++) {
                for (i = 1; i <= k; i++) {
                    if (i == 1 || i == k) {
                        count[i] = 1;
                        count1[i] = 1;
                    } else {
                        count1[i] = count[i];
                        count[i] = count1[i - 1] + count1[i];
                    }
                    System.out.print(count[i] + " ");
                }
                System.out.print("\n");
            }
        }