饮料卖两块钱一瓶,两个空瓶子或者四个瓶盖均可以换一瓶新的饮料。10块钱可以喝多少瓶饮料?
public static int getDrinkCount(int money ,int price){ int bottleCount = 2; int capCount = 4; int bottle = 0; int cap = 0; int drinkCount = 0; drinkCount = money / price; bottle = drinkCount ; cap = drinkCount ; return getDrinkCount(drinkCount, bottle, cap, bottleCount, capCount); } private static int getDrinkCount(int drinkCount,int bottle,int cap ,int bottleCount,int capCount){ int count = bottle / bottleCount + cap / capCount; drinkCount += count; bottle = bottle % bottleCount + count; cap = cap % capCount + count; System.out.println(count +"=="+bottle +"=="+cap); if (bottle < bottleCount && cap < capCount) { return drinkCount; } return getDrinkCount(drinkCount, bottle, cap, bottleCount, capCount); }