看java核心技术里一个例子public class welcome{public static void main(String[] args){String[] greeting=new String[3];greeting[0]="welcome to core java";greeting[1]="by Gay Horstmann";greeting[2]="and Gary Cornell";for(String g:greeting)Syste

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/22 09:07:24
看java核心技术里一个例子publicclasswelcome{publicstaticvoidmain(String[]args){String[]greeting=newString[3];gr

看java核心技术里一个例子public class welcome{public static void main(String[] args){String[] greeting=new String[3];greeting[0]="welcome to core java";greeting[1]="by Gay Horstmann";greeting[2]="and Gary Cornell";for(String g:greeting)Syste
看java核心技术里一个例子
public class welcome
{
public static void main(String[] args)
{
String[] greeting=new String[3];
greeting[0]="welcome to core java";
greeting[1]="by Gay Horstmann";
greeting[2]="and Gary Cornell";
for(String g:greeting)
System.out.println(g);
}
}
代码无误,执行也正常.可是for(String g:greeting)这一句我看不懂,这是for循环么.

看java核心技术里一个例子public class welcome{public static void main(String[] args){String[] greeting=new String[3];greeting[0]="welcome to core java";greeting[1]="by Gay Horstmann";greeting[2]="and Gary Cornell";for(String g:greeting)Syste
for each语法.
for(String g:greeting)
System.out.println(g); 相当于
for(int i = 0; i < greeting.length; i ++ ) {
String g = greeting[i];
System.out.println(g);
}