首页 > 编程语言 > 详细

数组的使用

时间:2021-07-22 23:42:10      阅读:23      评论:0      收藏:0      [点我收藏+]

数组的使用

 

package com.zishi.Array;
?
public class ArrayDemo04 {
   public static void main(String[] args) {
       int [] arrays = {1,2,3,4,5};
?
       printArrays(arrays);
?
       System.out.println("");
       System.out.println("========================");
?
       int[] result = reverse(arrays);
       printArrays(result);
  }
?
   //反转数组
   public static int[] reverse(int[] arrays){
       int[] result = new int[arrays.length];
?
       //反转的操作
       for (int i = 0,j=result.length-1; i < arrays.length; i++,j--) {
           result[j] = arrays[i];
      }
?
?
       return result;
  }
?
?
   //打印数组元素
   public static void printArrays(int[] arrays){
       for (int i = 0; i < arrays.length; i++) {
           System.out.print(arrays[i]+" ");
      }
  }
?
}

 

数组的使用

原文:https://www.cnblogs.com/yizhifei/p/15046797.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!