public Bee anotherDay(){
flower = garden.findFlower();
int pol = 5;
bool=flower.extractPollen(pol);
if(bool=true){
hive.addPollen(pol);
}else{
++pol;
bool=flower.extractPollen(pol);
if(bool=true){
hive.addPollen(pol);
}else{
++pol; //etc.
}
}
代码的一点是:如何将此代码转换为循环?
1)use the findFlower() method on garden ot return a flower
2)use the extract pollen method on the flower with 5 as the initial paramater
3)If there isn't 5 pollen in the flower, the method returns false so try again with 4
4)If there isn't 4 try with 3 etc. until 0.
我想用一个for循环,但我不知道该怎么打出来的,如果该方法是成功的,返回真,所以我不要继续从花中获得5 + 4 + 3 + 2 + 1花粉。
首先,++ pol会增加值,而不是减少它。因此,你每次都要求越来越多的花粉。 – Jason
哈哈你还在为你的蜂箱工作吗? :P – Blub
哈哈是啊我是 - 这是我自学Java的一个练习,当我走的时候越来越困难=)它现在变得非常复杂了,尽管如此我可能不得不开始一些事情很快就会出现,所以它不会变得混乱和混乱。在我的工蜂提取花粉并将其转换为蜂蜜并从配置文件载入初始条件后,我将离开它。希望有一天我可以回来添加一个GUI,但我会离开,直到我已经牢牢掌握基础知识! – user2973447