-
XhstormR
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Test {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
int[] s = {1, 2, 3, 4, 5, 6};
for (int i : s) {
list.add(i);
}
Collections.reverse(list);
Object[] objects = list.toArray();
System.out.println(Arrays.toString(objects));
}
}代码以上,望采纳。
-
阿旭_
import java.util.Arrays;
public class Test8 {
public static void main(String[] args) {
// int[]s={1,2,3,4,5,6};怎么反序 {6,5,4,3,2,1}
int[] s = { 1, 2, 3, 4, 5, 6 };
for (int i = 0; i < s.length / 2; i++) {
s[i] = s[i] ^ s[s.length - 1 - i];
s[s.length - 1 - i] = s[i] ^ s[s.length - 1 - i];
s[i] = s[i] ^ s[s.length - 1 - i];
}
System.out.println("反序后:" + Arrays.toString(s));
}
}
-
AatroxC
import java.util.Arrays;
public class Test8 {
public static void main(String[] args) {
// int[]s={1,2,3,4,5,6};怎么反序 {6,5,4,3,2,1}
int[] s = { 1, 2, 3, 4, 5, 6 };
for (int i = 0; i < s.length / 2; i++) {
s[i] = s[i] ^ s[s.length - 1 - i];
s[s.length - 1 - i] = s[i] ^ s[s.length - 1 - i];
s[i] = s[i] ^ s[s.length - 1 - i];
}
System.out.println("反序后:" + Arrays.toString(s));
}
}
-
慕粉鸣少
public class main{
public static void main(String[] args){
int[] a={1,2,3,4,5,6};
for(int i=a.length-1;i>=0;i--){
system.out.print(a[i]);
}
}
}//一条代码即可,请采纳
-
qq_抱嫦娥O烤玉兔_03445798
int[] a = { 1, 2, 3, 4, 5, 6 };
for (int i = a.length - 1; i >= 0; i--) {
System.out.print(a[i]);
}
-
田心枫
import java.util.ArrayList;import java.util.Collections;
public class Main {
public static void main(String[] args) {
ArrayList arrayList = new ArrayList();
arrayList.add("A");
arrayList.add("B");
arrayList.add("C");
arrayList.add("D");
arrayList.add("E");
System.out.println("反转前排序: " + arrayList);
Collections.reverse(arrayList);
System.out.println("反转后排序: " + arrayList);
}
}反转前排序: [A, B, C, D, E]
反转后排序: [E, D, C, B, A]