這里為什么會報錯呢。
public class HelloWorld {
??? public static void main(String[] args) {
?? ??? ?
?? ??? ?// 定義一個長度為 3 的字符串數(shù)組,并賦值初始值
?? ??? ?String[] hobbys = { "sports", "game", "movie" };
?? ??? ?System.out.println("循環(huán)輸出數(shù)組中元素的值:");
?? ??? ?
?? ??? ?// 使用循環(huán)遍歷數(shù)組中的元素
?? ??? ?for(int=0;i<hobbys.length;i++){
?????????? System.out.println(hobbys[i]);
?? ??? ?}
}
2016-02-15
for循環(huán)里錯了 int i=0;? 這種小錯誤 都愛犯 仔細看就好了
2016-01-13
public class HelloWorld {
??? public static void main(String[] args) {
?????? ?
??????? // 定義一個長度為 3 的字符串數(shù)組,并賦值初始值
??????? String[] hobbys = { "sports", "game", "movie" };
??????? System.out.println("循環(huán)輸出數(shù)組中元素的值:");
?????? ?
??????? // 使用循環(huán)遍歷數(shù)組中的元素
??????? for(int i=0;i<hobbys.length;i++){
?????????? System.out.println(hobbys[i]);
??????? }
??? }
}
錯誤如下:
1、for循環(huán)中定義i的初值,要寫成 int i=0;
2、你在結(jié)尾處少打了一個大括號};