Reason for error

Can’t understand what and why the wrong output is coming.

@2304ambikagupta_35a5bee93bbf353e benchmark your code with this :

import java.util.*;

public class Main {

    public static void main(String[] args) {

        long[] fib = new long[30];
        fib[1] = 1;
        for (int i = 2; i < 30; i++) {
            fib[i] = fib[i - 1] + fib[i - 2];
        }

        Scanner sc = new Scanner(System.in);

        int testCases = sc.nextInt();
        int k = 1;

        while (testCases-- > 0) {
            int n = sc.nextInt();
            System.out.println("#" + (k++) + " : " + fib[n + 2]);
        }

    }
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.