数组取反值

package test_1;
//取反
public class test_4 {
    public static void main(String[] args) {
      int[] arr = {11,22,33,44,55};
      reverseArray(arr);  //调用取反方法
      print(arr);    //调用遍历打印方法
      }

 //取反方法 

    public static void reverseArray(int[] arr) {      
      for(int i=0; i< arr.length / 2 ; i++) {
      int temp = arr[i];
      arr[i]=arr[arr.length -1-i];
      arr[arr.length -1 -i] = temp;
        }
      }

//遍历打印方法

    public static void print(int[] arr) {
      for(int i=0; i< arr.length ; i++) {
        System.out.println(arr[i]);
        }
      }
}

posted @ 2020-05-10 18:25  雨曼晴川  阅读(1069)  评论(0编辑  收藏  举报