## Problem:

We have bunnies standing in a line, numbered 1, 2, ... The odd bunnies (1, 3, ..) have the normal 2 ears. The even bunnies (2, 4, ..) we'll say have 3 ears, because they each have a raised foot. Recursively return the number of "ears" in the bunny line 1, 2, ... n (without loops or multiplication).

bunnyEars2(0) → 0
bunnyEars2(1) → 2
bunnyEars2(2) → 5

## Solution:

public int bunnyEars2(int bunnies) {
if (bunnies == 0) return 0;
if (bunnies % 2 == 0) return 3 + bunnyEars2(bunnies-1);
else return 2 + bunnyEars2(bunnies-1);
}

1. Thank you!!

2. public int bunnyEars2(int bunnies) {
if(bunnies==0)return 0;
return bunnyEars2(bunnies-1)+3-bunnies%2;
}

3. public int bunnyEars2(int bunnies) {
return bunnies*5/2;
}

1. You have to do it without loops or multiplication.

4. public int bunnyEars2(int bunnies) {
if(bunnies==0)return 0;
if(bunnies==1)return 2;
if(bunnies==2)return 5;
return 5+bunnyEars2(bunnies-2);
}

5. public int bunnyEars2(int bunnies) {
if (bunnies == 0) return 0;
if (bunnies % 2 == 0)
return 3 + bunnyEars2(bunnies-1);
else return 2 + bunnyEars2(bunnies-1);
}
question:
1 bunny = 2 ears; if bunnies %2 == 0 - yes, so add 3
2 bunny = 5 ears; if bunnies %2 == 0 - no, so add 2
3 bunny = 7 ears; if bunnies %2 == 0 - no 7%2 is 1, why does it

6. return (bunnies ==0)? 0 : 2 + (bunnies-1)%2 + bunnyEars2(bunnies-1);

7. public int bunnyEars2(int bunnies) {
if(bunnies == 0) {
return 0;
}
if(bunnies % 2 == 1) {
return 2 + bunnyEars2(bunnies - 1);
} else {
return 3 + bunnyEars2(bunnies - 1);
}
}

8. Can you try it with for loop

1. no, because the challenge states, "(without loops or multiplication)."

It may be completed easily with loops, but that is not the point.

9. public int bunnyEars2(int bunnies) {
if (bunnies == 0) return 0;
if (bunnies == 1) return 2;
return 5 + bunnyEars2(bunnies - 2);
}

1. The idea here is simple, every 2 bunnies is 5 ears. Lines 2 and 3 remove the need for a %2 all together.

hope that helps.

10. public int bunnyEars2(int bunnies) {
if(bunnies==0) return 0;
return (bunnies%2)==0?3+bunnyEars2(bunnies-1):2+bunnyEars2(bunnies-1);
}