幫忙看看哪里錯了
public class HelloWorld {
? ? public static void main(String[] args) {
// 定義一個長度為 3 的字符串?dāng)?shù)組,并賦值初始值
String[] hobbys = { "sports", "game", "movie" };
System.out.println("循環(huán)輸出數(shù)組中元素的值:");
// 使用循環(huán)遍歷數(shù)組中的元素
int i = hobbys.length;
int j;
for(j=0;j<=i;j++){
? ?System.out.println(hobbys[i]);
}
這個哪里有錯誤?。?/p>
2017-06-05
for(int j=0;j<=i;j++){}
?一般把int寫在for里面
還有就是你輸出的目標(biāo)寫錯了[j]
2017-06-16
int i = hobbys.length;
int j;
for(j=0;j<i;j++){
? ?System.out.println(hobbys[j]);
}
2017-06-11
循環(huán)里for (int ?j= 0; j < i; j++) ? 你的i的值是5,而數(shù)組只能到hobbys[4]。hobbys[5]的話就訪問越界啦。
2017-06-10
這節(jié)課還有個知識點(diǎn).length
2017-06-07
for(int j =8;表達(dá)式;增加方法)
2017-06-05
{ ?
String[] hobbys = {"sports", "game", "movie"};
System.out.println("循環(huán)輸出數(shù)組中元素的值:");
int i = hobbys.length;
for (int ?j= 0; j < i; j++) {
System.out.println(hobbys[j]);
? ? ? ?}
}
這樣就能實(shí)現(xiàn)正常輸出啦
2017-06-05
for(j=0;j<=i;j++){
? ?System.out.println(hobbys[i]);
}
?你把數(shù)組中的[i]換成[j].即可。
2017-06-05
好像 還有錯誤。。。。?System.out.println(hobbys[i]); ?i換成j
2017-06-05
int j; 要賦值,不賦值會報(bào)錯的,濃濃的js風(fēng)格 0.0