喝汽水问题
来源:互联网 发布:知象科技 李凌 编辑:程序博客网 时间:2024/04/30 01:06
共有500瓶汽水,每喝完1瓶后得到1个空瓶子,每3个空瓶子 又可以换1瓶汽水,喝掉以后又得到一个空瓶子,通过编程
计算出总共能喝多少瓶汽水,最后还剩余多少个空瓶子?
package com.lovo.homework;
import javax.swing.JOptionPane;
public class DrinkWater {
public int full=500;
public int empty=0;
public int empty1=0;
public void cal(){
while(true){
full--;
empty++;
empty1++;
if(empty==3){
empty=0;
full++;
}
if(full==0){
break;
}
}
JOptionPane.showMessageDialog(null, "一共喝了:"+empty1+"\n还剩空瓶个数:"+empty);
}
public static void main(String[] args) {
DrinkWater drinkWater=new DrinkWater();
drinkWater.cal();
}
}
0 0
- 喝汽水问题
- 喝汽水问题
- 喝汽水问题
- 喝汽水问题
- 喝汽水问题
- 喝汽水问题
- 喝汽水问题
- 喝汽水问题
- 喝汽水问题
- 喝汽水问题
- 喝汽水问题
- 喝汽水问题
- 喝汽水
- 喝汽水
- 汽水瓶问题(能喝多少瓶汽水)
- 20块钱喝汽水数量最大化问题
- C语言:20元喝汽水问题
- Drools规则入门程序:喝汽水问题(^_^)
- LeetCode Validate Binary Search Tree
- 解决Docker build时 Sending build context to Docker daemon 过大的问题
- 水仙花数
- http://www.csdn.net/article/2015-08-06/2825395
- 黑马程序员——C语言之字符串指针
- 喝汽水问题
- [bzoj 1588] 营业额统计 SBT模板
- UART传输时序-转载
- Oracle 有表连接的connect by 的优化
- Axure登录和注册界面的学习
- java 之新特性--枚举(JDK5出现的)
- [LeetCode] Clone Graph(!!!!graph&dfs&bfs)
- android 自定义view 让文字飞起来
- PM2.5检测仪设计