Regarding recursion problem how it is returning the value 7

public class Main
{
public static void main(String[] args) {
System.out.println(fun(7));
}

public static int fun(int n){
    if(n==1){
        return 1;
        
    }else{
        return 1+fun(n-1);
    }
}

}

Hi @saurabhananta,
In this function fun you have used the recursion call fun(n-1) which will call fun(6) then fun(5) and so on … till f(1) where it will return 1 and then go to fun(2) will return 1 + what fun(1) has returned. So fun(2) will return 2 and then fun(3) will return what fun(2) returned+1 so it will return 3 …I hope you see the pattern here so fun(6) will return 1+ what fun(5) returned so it will return 6 and then fun(7) which is the original function it will return what fun(6) returned +1 so it will return 7 hence the output 7.