首页 > 编程语言 > 详细

算法 (1)

时间:2018-11-27 15:35:31      阅读:118      评论:0      收藏:0      [点我收藏+]

一、数组

颠倒数组元素的顺序:

package algorithm;

/**
 * 颠倒数组元素的顺序
 */
public class ReverseArray {

    public static void main(String[] args) {
        int array[] = {4, 3, 1, 9, 8};
        reverseArray(array);
        for(int a : array){
            System.out.print(a + " ");
        }
    }

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

 

算法 (1)

原文:https://www.cnblogs.com/tenWood/p/10026472.html

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