首页 > 编程语言 > 详细

数组使用

时间:2020-11-23 19:32:46      阅读:25      评论:0      收藏:0      [点我收藏+]

package array;

public class ArraysDemo04 {
public static void main(String[] args) {
int[] arrays = {1,2,3,4,5};

    //JDK1.5以上,没有下标

// for (int array : arrays) {
// System.out.println(array);
// }

    int[] reverse = reverse(arrays);
    printArray(reverse);
}
//打印数组元素
public static void printArray(int[] arrays){
    for (int i = 0; i < arrays.length; i++) {
        System.out.print(arrays[i]+" ");
    }
}

//反转数组
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;
}

}

数组使用

原文:https://www.cnblogs.com/bizhenghe/p/14026072.html

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