public class Cola
{
public static int getNum(int m)
{
//初始化购买数为0
int x=0;
while(x<m)
{
//判断购买的可乐及瓶盖是否达到要喝的数量
if(x+x/2>=m)
break;
else
x++;
}
//返回购买的可乐瓶数
return x;
}
public static void main(String[] args)
{
//验证代码是否正确,遍历下1-50
for(int x=1;x<=50;x++)
{
System.out.println("要喝"+x+"瓶,"+"需要买"+getNum(x)+"瓶");
}
}
}
public class CokeNum {
public static int cokeNum(int bottle0) {
int bottle = 1;
int buyNum = 1;
while (bottle < bottle0) {
buyNum++;
bottle++;
if (bottle % 3 == 0) {
bottle++;
}
}
return buyNum;
public class mianshiT {
public static void main(String[] args) {
int cishu=28;
int c=kele(cishu);
System.out.println(c);
}
public static int kele(int cishu) {
int c=0;
int huan=0;
int counts=0;
while(c!=cishu){
c++;
huan++;
counts++;
if(c==cishu){
break;
}
if(huan==3){
c++;
huan=1;
}
}
return counts;
}
}
不知道自己写的对不对...求大神指点一二