【问题标题】:Java Array Set Up [duplicate]Java数组设置[重复]
【发布时间】:2015-10-05 07:50:24
【问题描述】:

我正在为我的一个项目编写代码,它需要我编写一个数组。如何实现评论 5a?我得到评论 5 对吗?

// 4. declare an array of players

Player [] team = new Player[];

// 5. loop over teamsize

for( int index = 0; index < team.length; index++)

// 5a. instantiate the i'th team member

【问题讨论】:

标签: java arrays


【解决方案1】:

是的,你确实答对了 5 个,但我建议如下:

int length = team.length // to avoid unnecessarily calling it every iteration
for (int index = 0 ; index < length ; index++) {
   // ...
}

对于 5a,只需实例化一个 Player 类。如果您不知道该怎么做,请阅读Java tutorials。他们非常有帮助。

5a 的另一件事,指令说 i'th 团队成员,这只是意味着 nth(因为 iindex 的通用变量名,这是您已经在使用的)

【讨论】:

    猜你喜欢
    • 2018-09-26
    • 2013-12-28
    • 1970-01-01
    • 2012-11-21
    • 2014-09-09
    • 2021-10-21
    • 2013-04-19
    相关资源
    最近更新 更多