for_each 循环与 for 循环的对比
public class ForEach{
public static void main(String[] args) {
int[] a = {1,2,3,4,5,6,7,8};
int i;
for(i=0;i<a.length;i++){
System.out.printf(a[i]+"\t");
}
// for_each 循环
for(int b:a){
System.out.printf(b+"\t");
}
// for_each 循环字符串
String[] s = {"norse","mouse","ear"};
for(String b:s){
System.out.printf(b+"\t");
}
}
}
网友评论