day05-数组的操作_数组遍历
This commit is contained in:
25
day05/src/com/inmind/array01/Demo05.java
Normal file
25
day05/src/com/inmind/array01/Demo05.java
Normal file
@@ -0,0 +1,25 @@
|
||||
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("程序结束");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user