数组的遍历输出

遍历数组,说的就是对数组当中的每一个元素进行逐一处理.默认的处理方式就是打印输出.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

public class test017 {
public static void main(String[] args) {
int[] array = {1,2,324,12,234,15,12,51,234,21};

//第一种方法,将array的每一个元素逐次赋值给i
for (int i : array) {
System.out.println(i);
}

System.out.println("======================");
//第二种方法,将i当做array的下标,通过i的不断增加,来打印array数组,且i小于array.length
for (int i = 0; i < array.length;i++)
{
System.out.println(array[i]);
}
}
}