I don't understand how this method works.
I run the recur method and the output starts at 98, gets incremented and I can't seem to understand what's going on later. The output I expected is:
a=98
a=99
a=99
a=100
a=100
a=101
But the actual output is:
a=98
a=99
a=100
a=101
a=100
a=99
I found this exercise in a local java testing forum. So, any explanations would be useful for me.
public class Test {
public static void main(String[] args) {
recur(98);
}
public static void recur(int a) {
if (a <= 100) {
System.out.println("a=" + a);
recur(++a);
System.out.println("a=" + a);
}
}