java程序运行问题
class Exercise
{
public static void main(String[] args)
{
int[][]a = new int [10][10];
for(int i = 0;i < 10;i++)
for(int j = 0;j < 10;j++)
{
if((j == 1)|(i==j))
{
a[i][j] = 1;
}
else
a[i][j] = a[i-1][j-1] + a[i-1][j];
}
for(int i= 0;i < 10; i++)
{
for(int j = 0;j < i;j++)
System.out.printf(" ",a[i][j]);
}
}
}
请大神给我看看这个程序哪错了?编译能通过,但运行就出现问题了
[解决办法]
public class Exercise {
public static void main(String[] args) {
int[][] a = new int[10][10];
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if ((j == 1)
[解决办法]
(i == j)) {
a[i][j] = 1;
} else {
if ((i == 0)&&(j!=0) ){
a[i][j] = 0;
} else if ((j == 0)&&(i!=0)) {
a[i][j] = 0;
}else {
a[i][j] = a[i-1][j-1] + a[i-1][j];
}
}
}
}
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++){
System.out.print(" "+a[i][j]);
}
System.out.println();
}
}
}