问题:
一个人买汽水,一块钱一瓶汽水,三个瓶盖可以换一瓶汽水,两个空瓶可以换一瓶汽水
问20块钱可以买多少汽水?
注意:使用递归
1 public class RecursionBottle { 2 public static void main(String[] args){ 3 int result=Recursion(5,0,0); 4 System.out.println(result); 5 } 6 7 public static int Recursion(int Total,int Bottle,int Caps){ 8 Bottle=Bottle%2; 9 Caps=Caps%3; 10 Bottle=Bottle+Total; 11 Caps=Caps+Total; 12 if(Bottle<2&&Caps<3) { 13 return Total; 14 } 15 else{ 16 return Recursion((Bottle/2+Caps/3),Bottle,Caps)+Total; 17 } 18 } 19 }