Discuss / Java / 倒序数组

倒序数组

Topic source

福尔罗斯

#1 Created at ... [Delete] [Delete and Lock User]

import java.util.Arrays;

public class Main {

public static void main(String[] args) {

int[] ns = { 1, 4, 9, 16, 25 };
Arrays.sort(ns);
for(int i = 0; i < ns.length/2 ; i++)

{

int j = ns.length - i -1;
int temp = ns[i];
ns[i] = ns[j];
ns[j] = temp;
}

System.out.println(Arrays.toString(ns));
}

}


  • 1

Reply