数组正遍历,数组倒遍历

 1 package com.pang.array_demo;
 2 
 3 public class Array_Demo {
 4     public static void main(String[] args) {
 5         int[] arr = {1,2,3,4,3,45};
 6         arrayDemo(arr);
 7         System.out.println("===========");
 8         arrayDemo02(arr);
 9     }
10 
11     // 数组正遍历
12     public static void arrayDemo(int[] arr) {
13         for (int i = 0; i < arr.length; i++) {
14             System.out.println(arr[i]);
15         }
16     }
17 
18     // 数组倒遍历
19     public static void arrayDemo02(int[] arr) {
20         for (int i = arr.length - 1; i >= 0; i--) {
21             System.out.println(arr[i]);
22         }
23     }
24 }

 

posted @ 2017-06-16 16:56  更好遇见你  阅读(1557)  评论(0编辑  收藏  举报