I am getting error as "Exception in thread "main" java.lang.NullPointerException at Pascal.main(Pascal.java:8)"
public class Pascal {
public static void main(String args[]){
int rows,i,j,k;
rows=Integer.parseInt(args[0]);
double pas[][]= new double[rows][];
pas[0][0]=1; //the line of error
for (i=1;i<=rows;i++){
for (j=1;j<=i;j++){
pas[i-1][j-1]=pas[i-2][j-2]+pas[i-2][j-1];
}
}
for(i=0;i<rows;i++){
for(j=0;j<=i;j++){
System.out.print(pas[i][j]);
}
System.out.println("");
}
}
}
Why I am getting error on line: pas[0][0]=1;
[], that means all of the 2d arrays are NULL. So you would either need to define that size when initializing the variable OR you would need to add the second array in the for-loop such as:pas[0] = new double[size];then dopas[0][0] = 1;