Lets take the 5 as an example: bunnyEars(5) returns 2 + bunnyEars(4) bunnyEars(4) returns 2 + bunnyEars(3) bunnyEars(3) returns 2 + bunnyEars(2) bunnyEars(2) returns 2 + bunnyEars(1) bunnyEars(1) returns 2 + bunnyEars(0) bunnyEars(0) returns 0 because this is specified as such
So if you put this together: bunnyEars(5) returns 2 + (2 + (2 + (2 + (2 + 0))))
First you give a value for the int variable bunnies when the bunnyEars() method is called. Then inside the method it checks if the value of bunnies is zero. If it is zero, then returns the values zero, giving the number of bunnyEars as zero (Obviously if the number of bunnies is zero, how can there be any ears). With this the method returns.
If the bunnies is not equals to zero, return the value corresponding to the following statement; 2 + bunnyEars(bunnies-1)
Let's analyze this with an example. Lets say the number of bunnies=5. Then the method does not return zero, instead it returns the above value.
2 + bunnyEars(bunnies-1) can be written as 2 + bunnyEars(4) since initially bunnies=5. Then bunnyEars() method is called again within the same method itself for the value bunnies=4. This goes on as follows;
Calling bunnyEars with a negative value will end: - the bunny parameter will be decreased until it becomes Integer.MIN_VALUE - another decrease will make it Integer.MAX_VALUE - it will be decreased further until it becomes 0
However, the check could be better. Perhaps as follows:
All depending on what you actually want bunnyEars to calculate