数组的遍历


数组的遍历,读取数组的值

public class Test02 {
public static void main(String[] args) {
int[]a = new int [4];

//初始化数组元素的值
for(int i =0;i a[i] = 100*i;
}

//for循环读取元素的值

for(int i = 0;i System.out.println(a[i]);
}


//foreach循环:用于读取所有元素的值,但不能修改元素的值
for(int b:a) {
System.out.println(b);
}
}
}