Not able to understand what is happening here. The print statement is printing the output as 6, but the func function is return output as 3.
public class Main
{
static int func(int[] arr,int n,int sum){
if (n==0) return sum;
sum+=arr[n];
System.out.println("Inside functions "+sum);
func(arr,n-1,sum);
return sum;
}
public static void main(String[] args) {
int[] arr={0,1,2,3,4,5,6,7,8,9};
int ans=func(arr,3,0);
System.out.println(ans);
}
}