代码展示:
public class try4 {
public static void main(String[] args)
{
String[] tt = new String[3];
tt[0]="haha";
tt[1]="nana";
tt[2]="lala";
for(int x=0;x<=tt.length-1;x++) {
System.out.println("遍历数组第"+x+"个元素是:"+tt[x]);
}
}
}
或者:
public static void main(String[] args)
{
String[] tt = new String[3];
tt[0]="haha";
tt[1]="nana";
tt[2]="lala";
int count = 1;
for(String x:tt) {
System.out.println("遍历数组第"+count+"个元素是:"+x);
count++;
}
}
结果展示: