I am getting correct for two test cases, but i am getting a runerror for the third test case.
import java.util.*;
public class fibonaccipattern {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
n=sc.nextInt();
if(n<100 && n>0) {
int fibn;
int ans=0;
for(int i=n;i>=1;i–) {
ans+=i;
}
fibn=ans;
int [] arr= new int[fibn];
arr[0]=0;
arr[1]=1;
for(int i=2;i<arr.length;i++) { //to find the fibonacci sequence and store in the array
arr[i]=arr[i-1]+arr[i-2];
}
int row=1;
int nst=1;
int k=0;
while(row<=n) {
for(int cst=1;cst<=nst;cst++) {
System.out.print(arr[k]+"\t");
k++;
}
row=row+1;
nst++;
System.out.print("\n");
}
}
else {
}
}
}