创建一维数组,长度为20,元素索引值为索引的二倍,奇数为负偶数为正,然后对数组排序

2/22/2017来源:ASP.NET技巧人气:3041

import java.util.Arrays; public class ArrayCreate{ public static void main(String[] args) { int[]a = new int[20]; for (int i = 0 ;i < 20 ;i++ ){ a[i] = i*2; if (i%2!= 0) { a[i] = -1*a[i]; } } Arrays.sort(a); for( int i = 0 ;i < 20 ;i++) System.out.PRint(a[i]+" "); } }