package com.tiedandan.base;
public class forimprove {
public static void main(String[] args) {
int []a=new int[5];
int [][]b =new int[5][5];
//一维数组正常for循环遍历
for (int i = 0; i <a.length ; i++) {
System.out.print(a[i]+"\t");
}
System.out.println();
System.out.println("===========+++++++++++++++++++++++");
//一维数组增强for循环:语法a.for相当于把数组a中的所有元素都传给i,然后遍历输出i。
for (int i : a) {
System.out.print(i+"\t");
}
System.out.println();
System.out.println("============+++++++++++++++++++");
//二维数组正常for循环
for (int i = 0; i <b.length ; i++) {
for (int j=0;j<b.length;j++){
System.out.print(b[i][j]+"\t");
}
System.out.println();
}
//二维数组增强for循环:b.for相当于把二维数组b中的所有一维数组都传给ints,
// 然后ints.for相当于把一维数组里的所有元素全部传给anint,最后输出anint即可。
for (int[] ints : b) {
for (int anInt : ints) {
System.out.print(anInt+"\t");
}
System.out.println();
}
}
}