标签:ever div algorithm reverse print temp nbsp 组元 数组
一、数组
颠倒数组元素的顺序:
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; } } }
标签:ever div algorithm reverse print temp nbsp 组元 数组
原文地址:https://www.cnblogs.com/tenWood/p/10026472.html