I am trying to understand how recursive works. Below is a code of If-else block.
public class Test {
public void test(int count){
if(count ==1){
System.out.println("Inside IF");
}
else{
System.out.println("Inside Else");
test(--count);
System.out.println("TEST");
}
}
public static void main(String[] args) {
Test t = new Test();
t.test(5);
}
}
The Output for the above code is
Inside Else Inside Else Inside Else Inside Else Inside IF TEST TEST TEST TEST
Could someone please help me understand why the TEST has been printed 4 times.
Thanks