28 lines
825 B
Java
28 lines
825 B
Java
package com.inmind.array01;
|
|
|
|
/**
|
|
* 数组的遍历
|
|
* 遍历:将数组中的每个数据,一一展示
|
|
*/
|
|
public class Demo05 {
|
|
public static void main(String[] args) {
|
|
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8};//100个
|
|
//请将数组中每个值打印输出
|
|
/*System.out.println(arr[0]);
|
|
System.out.println(arr[1]);
|
|
System.out.println(arr[2]);*/
|
|
//使用for循环来遍历数组(正向for循环)
|
|
for (int index = 0; index < arr.length; index++) {
|
|
System.out.println(arr[index]);
|
|
}
|
|
System.out.println("---------");
|
|
|
|
//使用for循环来遍历数组(反向for循环)
|
|
for (int i = arr.length - 1; i >= 0; i--) {
|
|
System.out.println(arr[i]);
|
|
}
|
|
|
|
System.out.println("程序结束");
|
|
}
|
|
}
|