0

I developed this code to calculate the factorial in java by the dynamic approach. But it's throwing an exception NULLPOINTER, here is my code:

public class test { int fact[];int i; int fact(int n) { for ( i =2;i<n;i++) { fact[0]=1; fact[1]=1; fact[i]=fact[i]*fact[1]*fact[0]; }return fact[n]; } public static void main(String args[]) { int N=5; test t=new test(); int arr[]=new int[N]; for(int j=0;j<N;j++) { arr[j]= t.fact(j); } for(int j=0;j<N;j++) { System.out.println(arr[j]); } } } </code></pre>

I am a beginner in java, please can you correct my mistake. Thanks in advance.

0 Answers0