例如輸入123456,打印出654321,但是輸入的數(shù)是幾位的不確定。
1 回答
已采納

Ling36
TA貢獻(xiàn)1條經(jīng)驗(yàn) 獲得超1個贊
import java.util.Arrays;
public class HelloWorld {
public static void reSort(int[] arr){
int n = arr.length;
for(int i = 0; i < n/2 - 1; i++){
swap(arr,i,n-1-i);
}
}
public static void swap(int[] arr, int a, int b){
int temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
public static void main(String[] arg) {
int[] arr = {1,2,3,4,5,6,7};
reSort(arr);
System.out.println(Arrays.toString(arr));
}
}
添加回答
舉報
0/150
提交
取消