So, I try to automate this script for Euler project 15. I don't understand why in this version the automation won't work, in the last piece of code.
BigInteger b = new BigInteger("1");
BigInteger Arr [][] = new BigInteger [20][20];
//add 1 to 20.
for(int i=1; i<=20;i++) {
String I = Integer.toString(i);
b = new BigInteger(I);
Arr[1][i-1] = b;
}
The following piece of code works. So i try automated it, which does not work. Help me find out why.
Arr[2][1] = Arr[1][2];
for(int i = 2; i<20; i++) {
Arr[2][i] = Arr[2][i-1].add(Arr[1][i]);
System.out.println(Arr[2][i]);
}
Arr[3][2] = Arr[2][3];
for(int i = 3; i<20; i++) {
Arr[3][i] = Arr[3][i-1].add(Arr[2][i]);
System.out.println(Arr[3][i]);
}
Arr[4][3] = Arr[3][4];
for(int i = 4; i<20; i++) {
Arr[4][i] = Arr[4][i-1].add(Arr[3][i]);
System.out.println(Arr[4][i]);
}
Here I tried to automate the code. but it gives me an:
Exception in thread "main" java.lang.NullPointerException at Problem15.main(Problem15.java:45)
for(int c=2; c<20; c++) {
Arr[c][c-1] = Arr[c-1][c];
for(int i = c; i<20; c++) {
System.out.println(Arr[c][i-1]);
Arr[c][i] = Arr[c][i-1].add(Arr[c-1][i]);
System.out.println(Arr[c][i]);
}
System.out.println("hi");
}