克隆和for循环的问题 [英] issues with clone and for loop
本文介绍了克隆和for循环的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void buildDeck(ArrayList<Card> Monsters, ArrayList<Card> Spells) {
int monstersQouta = 15;
int spellsQouta = 5;
Random r = new Random();
for (; monstersQouta > 0; monstersQouta--) {
int randomIndex = r.nextInt(monsters.size());
MonsterCard monster = (MonsterCard) monsters.get(randomIndex);
MonsterCard clone = new MonsterCard(monster.getName(),
monster.getDescription(), monster.getLevel(),
monster.getAttackPoints(), monster.getDefensePoints());
clone.setMode(monster.getMode());
clone.setHidden(monster.isHidden());
clone.setLocation(Location.DECK);
deck.add(clone);
}
我需要知道我们在这里使用的原因 clone()
以及此代码中的for循环如何工作
I need to know why we used here clone()
and how this for loop in this code works
推荐答案
正如Andy Turner所说的第一个问题:
As Andy Turner said for your first question :
clone()未被使用。恰好这个变量叫做clone,但是对代码没有语义重要性。
clone() is not being used. It just so happens that the variable is called clone, but that has no semantic importance to the code.
关于 for
语句他由3个部分组成,每个部分用一个;
分隔,并且没有一个部分有义务在那里:
Concerning the for
statement he's composed of 3 parts ,each separated by one ;
, and none of them is obligated to be there :
- 第一部分是您可以或不可以声明增量变量的地方:
int i = 0;
- 第二部分是您必须将评估结果放在布尔值上的位置:
kappa.lengh> = i;
- 第三部分是修改变量值的地方:
i - ;
- The first part is where you can, or not, declare your incremental variable :
int i = 0;
- The second part is where you must put an evaluation resulting on a boolean value :
kappa.lengh >= i;
- The thrid part is where you will modify the variable(s) values :
i--;
由于这些部分都没有义务,你可以像这样写一个正确的for循环: for(;;)
。
Since none of these parts are obligated, you could write a correct for loop like this one : for(;;)
.
这是文档的链接:用于声明。
这篇关于克隆和for循环的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文