日期:2014-05-19 浏览次数:20873 次
package homework; public class Test1 { public static void main(String[] args) { int sum = 50; int i = 50; int chuShu = 0; int yuShu = 0; for (; i > 2; i--) { chuShu = i / 3; yuShu = i % 3; sum += chuShu; i = chuShu + yuShu; } System.out.println(sum); //System.out.println(2/3); //System.out.println(2%3); } } /* * * 1、 50 瓶可乐,3 空瓶换一瓶,一共能喝多少? * * 笔算结果为 50+16+6+2=74 * * 可是输出结果为73,觉得过程没有错,不知道错在哪儿? * */
int sum = 50; int i = 50; int chuShu = 0; int yuShu = 0; for (; i >2; i--) { chuShu = i / 3; yuShu = i % 3; sum=sum+chuShu; if(i>2) i=1+chuShu + yuShu; else{ i=chuShu + yuShu; } } System.out.println(sum); //输出结果 74