public class CountPingzi {public static void main(String[] args) {CountPingzi c = new CountPingzi();System.out.println(c.countPingzi(40));}public int countPingzi(int money){int result = money/2;//1.定义空瓶子数量int countEmpty = money/2;while(countEmpty>=2){//计算空瓶子可以换多少饮料int i = countEmpty / 2;result += i;//保留余数(就是空瓶子的数量),然后需要加上每次换到的新的饮料的数目icountEmpty = countEmpty%2 + i;}return result;}}
700字范文,内容丰富有趣,生活中的好帮手!