代码: public class main{ final static int kp=2; final static int pg=3; public static void main(string[]args) throws classnotfoundexception, instantiationexception, illegalaccessexception{ int time,i=1; int kongping,pinggai; int duihuan; time=20;kongping=20;pinggai=20; while(kongping/kp>=1||pinggai/pg>=1){ duihuan=kongping/kp+pinggai/pg; time+=duihuan; system.out.println("第"+i+"次:使用"+kongping+"个空瓶和"+pinggai+"个瓶盖兑换了"+duihuan+"瓶"); system.out.println("剩余"+kongping%kp+"个空瓶和"+pinggai%pg+"个瓶盖"); kongping=kongping%kp+duihuan; pinggai=pinggai%pg+duihuan; system.out.println("目前喝了"+time+"瓶"); system.out.println("喝完后剩余"+kongping+"个空瓶和"+pinggai+"个瓶盖"); i++; } }