Files
javaSE-0113/day05/src/com/inmind/array01/Demo05.java

26 lines
733 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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