public class testing
{
public static void printnum(int a)
{
System.out.println( a);
if(a <= 3)
{
System.out.println("recursed");
printnum(a+1);
}
System.out.println( a);
}
public static void main(String...s)
{
printnum(1);
}
}
output:
1
2
3
3
2
1
I expected the program to end at last 3 but I do not understand where are the next '2' and '1' coming from? How and why is it decrementing?