}
}
以上为代码,有问题但不知道怎么改
先不看你的算法,单纯的从java的语法及你写的测试方法出发:
public YanghuiTri() {
this(N);
}
public static void main(String args[]){
// 只写了引用,却没有写对象
// 正确的为YanghuiTri oa = new YanghuiTri(10);
YanghuiTri oa = new (10);
// 和上面的变量同名了,并且没有用到,直接删除
Scanner oa=new Scanner(System.in);
// full()已经在你的构造函数中调用过了,直接删除
oa.full();
oa.show();
}
public class TriangleArray {
public static void main(String[] args) {
final int NMAX = 10;
// allocate triangular array
int[][] odds = new int[NMAX + 1][];
for (int n = 0; n <= NMAX; n++)
odds[n] = new int[n + 1];
// fill triangular array
for (int n = 0; n < odds.length; n++)
for (int k = 0; k < odds[n].length; k++) {
/*
* compute binomial coefficient n*(n-1)*(n-2)*...*(n-k+1)/(1*2*3*...*k)
*/
int lotteryOdds = 1;
for (int i = 1; i <= k; i++)
lotteryOdds = lotteryOdds * (n - i + 1) / i;
odds[n][k] = lotteryOdds;
}
for (int[] row : odds)
{
for (int odd : row)
System.out.printf("%4d", odd);
System.out.println();
}
}
}
如需学习其他算法请参考我的博客:https://blog.csdn.net/zhanglide0526/article/details/120754067?spm=1001.2014.3001.5502