Why is this wrong

import java.util.*;
public class Main {

static int resul=0;

public static void main(String args[]) {


	Scanner sc=new Scanner(System.in);
	int T=sc.nextInt();
	for(int i=1 ; i<=T ; i++)
	{
		int n=sc.nextInt();
		
		ca(n , "a");
		ca(n , "b");
		System.out.println(  "#" + n + " : " + resul  );
		resul=0;
	}
 
	
 } 


static void ca(int n , String ans)
{
	if(n==0) return;

	if(ans.length()>=n) 
	{
		resul=resul+1;
		return;
	}
	
	
	if(ans.charAt(ans.length()-1)=='a')
	{
		ca(n , ans+"a");
		ca(n , ans+"b");
	}
	
	if(ans.charAt(ans.length()-1)=='b')
	{
		ca(n , ans+"a");
	}



}

}

If observed carefully , we can identify that this is a problem for fibonacci series. This is because at the nth place , there are two possibilities.
Possibility 1 : We can choose to place the current character as β€˜a’. If so , then it doesn’t matter whether we placed β€˜a’ or β€˜b’ at the previous position. The total number of ways in this possibility would equal to f(n-1)
Possibility 2 : We can place the current character as β€˜b’. However we can only do it if the previous character was not β€˜b’ . Hence the total number of ways for this case must be f(n-2)
We add these two possibilities up and obtain the recursive relation
f(n) = f(n-1) + f(n-2)
This is clearly the recursive relation for Fibonacci Series .

import java.util.*;

public class Main {
static int resul = 0;

public static void main(String args[]) {
	Scanner sc = new Scanner(System.in);
	int T = sc.nextInt();
	for (int i = 1; i <= T; i++) {
		int n = sc.nextInt();
		ca(n);
		System.out.println("#" + i + " : " + ca(n+2));
		resul = 0;
	}
}

static int ca(int n) {
	if (n == 0 || n == 1) {
		return n;
	}
	return ca(n - 1) + ca(n - 2);
}

}

but your ans is also not accepting , showing all results wrong

i think there is error in compiler , thats why it is not accepting code , i tried to submit direclty with iteration for finding fibonacci number corresponding , it is not accepting that also , pls look into a matter

print this line System.out.println("#" + i + " : " + ca(n+2)); Instead of this line System.out.println("#" + n + " : " + ca(n+2));

import java.util.*;

public class Main {
static int resul = 0;

public static void main(String args[]) {
	Scanner sc = new Scanner(System.in);
	int T = sc.nextInt();
	for (int i = 1; i <= T; i++) {
		int n = sc.nextInt();
		ca(n);
		System.out.println("#" + i + " : " + ca(n+2));
		resul = 0;
	}
}

static int ca(int n) {
	if (n == 0 || n == 1) {
		return n;
	}
	return ca(n - 1) + ca(n - 2);
}

}