day05--数组的操作_数组的遍历(重点)

This commit is contained in:
2026-09-18 11:31:09 +08:00
parent 91fbabc2f9
commit 25277905ff
+27
View File
@@ -0,0 +1,27 @@
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("程序结束");
}
}