I need little help with this simple problem. I recieved a compiler error, but
I don't know how to remove this error.
Showing error in this line int n = totalTree(num);
,
here is my code:
public class TotalNumberOfBinaryTrees {
//static int elementCount = 50;
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int test =sc.nextInt();
while(test>0){
int num = sc.nextInt();
int n = totalTree(num);
System.out.println("totalTree"+n);
test--;
}
}
public int totalTree(int n) {
if (n == 1 || n == 0)
return 1;
else {
int left = 0;
int right = 0;
int sum = 0;
for (int k = 1; k <= n; k++) {
left = totalTree(k - 1);
right = totalTree(n - k);
sum = sum + (left * right);
}
return sum;
}
}
}