结果:
循环输出数组中元素的值:sports
循环输出数组中元素的值:game
循环输出数组中元素的值:movie
public static void main(String[] args) {
String[] hobbys = {"sports", "game", "movie" };
for(int i=0;i<hobbys.length;i++){
System.out.println("循环输出数组中元素的值:"+hobbys[i]);
}
}
}
你的代码,文字信息在for循环内,执行时会遍历输出,将文字语句在for循环外即可:
public static void main(String[] args) { String[] hobbys = { "sports", "game", "movie" }; System.out.println("循环输出数组中元素的值:"); for(int i=0;i<hobbys.length;i++){ System.out.println(hobbys[i]); } } }}