A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© -天然呆ノ   /  2014-9-30 19:32  /  2621 人查看  /  22 人回复  /   1 人收藏 转载请遵从CC协议 禁止商业使用本文

回复 使用道具 举报
  1. class Test{
  2.         public static void main(String[] args) {
  3.                 System.out.println(getBuyCount(28));
  4.                 System.out.println(getBuyCount(50));
  5.         }
  6.         /**
  7.         * number:the number of people that need Coca-Cola
  8.         */
  9.         public static int getBuyCount(int number){
  10.                 int buyCount=0;//the number of Coca-Cola that need to buy
  11.                 int bottleCap=0;//the number of caps of bottles of Coca-Cola
  12.                 int bottleCount=0;//the number of Coca-Cola that actually get
  13.                 while(bottleCount<number)
  14.                 {
  15.                         buyCount++;
  16.                         bottleCap++;
  17.                         if (bottleCap==3) {
  18.                                 bottleCap=0;
  19.                                 bottleCount++;
  20.                                 bottleCap++;
  21.                         }
  22.                         bottleCount++;
  23.                 }
  24.                 return buyCount;
  25.         }
  26. }
复制代码
回复 使用道具 举报
12
您需要登录后才可以回帖 登录 | 加入黑马