public static int[] reverse(int[] list) {
int[] result = new int[list.length];
for (int i = 0, j = result.length - 1; i < list.length; i++, j--) {
result[j] = list[i];
}
return result;
}
示例
public class TiaoShi {
public static void main(String[] args) {
int[] list1 = { 1, 2, 3, 4, 5, 6 };
int[] list2 = reverse(list1);
for (int i : list2) {
System.out.print(i+”, “);
}
}
public static int[] reverse(int[] list1) {
int[] result = new int[list1.length];
for (int i = 0, j = result.length - 1; i < list1.length; i++, j--) {
result[j] = list1[i];
}
return result;
}
}
//输出结果6, 5, 4, 3, 2, 1,