如何将下面的代码转换为常规的 java for 循环?

请参阅下面的代码我遇到了不同的问题,我想转换为常规的 forloop 但没有用。原始代码无法编译,一直说 string 和 int 之间不匹配

for (i = array = list.length, b = 0; b < i; ) {
  ...
  b++;
}


蝴蝶刀刀
浏览 117回答 1
1回答

手掌心

i = array = list.length- 你不能做这个数组是 [] 和 list.length 是 int。所以它应该是这样的&nbsp; &nbsp; private String printList (Student [] list){&nbsp; &nbsp; &nbsp; &nbsp; String s = "";&nbsp; &nbsp; &nbsp; &nbsp; byte b;&nbsp; &nbsp; &nbsp; &nbsp; for (Student stud:list&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s+=" \n\t" + stud.toString();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return s;&nbsp; &nbsp; }但是 Student 类应该已经实现了正确的方法 toString();
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java