代码:
public class textBob {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int arr[]={1,7,8,6,5,5,6,9,6,6,8};
for(int i:arr){
System.out.print("["+i+"] ");
}
System.out.println();
char []brr={'I',' ','l','o','v','e',' ','y','o','u'};
for(char j:brr){
System.out.print(j);
}
}
}
使用方法:
for(type x:obj){
语句;
}
其中,foreach中使用了参数x,实现了对数组中所有数字的遍历;
结果;