var CreatureStory, zombie;
function CreatureStory(species, action) {
this.species = species;
this.action = action;
this.story = function(speciesNew, actionNew) {
this.species=speciesNew;
this.action=actionNew
console.log('The ' +this.species +' is about to ' +this.action +'.');
}
}
zombie = new CreatureStory('zombie', 'walk'); //variables passed in here.
zombie.story('zombieNew', 'walkNew'); // But how would I pass them in here?
colorName [i]如何使用Array更改值?
答案 0 :(得分:1)
String colorName [] = {"White", "Blue", "Red"};
您正在初始化包含白色,蓝色和红色的String
数组。在数组中,索引从0开始,因此White
变为第0个val,Blue
变为第1个,Red
变为第2个元素。
现在代码:
for(int i =0; i<3 ; i++)
{
Log.d("Favourite Colors", "" + colorName[i]);
}
这基本上是从0到2的循环,所以当你打印colorName[0]
时,它会打印白色等等。
无论如何,你想要实现什么目标?
答案 1 :(得分:0)
您能否提供有关您在此尝试实现的更多信息?我也会像这样重写你的代码
for(int i =0; i<colorName.length ; i++)
{
Log.d("Favourite Colors", "" + colorName[i]);
}