题解 | #数组倒转#
数组倒转
http://www.nowcoder.com/practice/3a90caee736a45e1ad70b1d4105dec5f
import java.util.Arrays; import java.util.Scanner;
public class Main { public static void main(String[] args) { int[] arr = new int[6]; Scanner scanner = new Scanner(System.in); for (int i = 0; i < arr.length; i++) { arr[i] = scanner.nextInt(); } System.out.println(Arrays.toString(arr));
//write your code here......
int temp = 0;
for(int m = 0,n = arr.length-1;m < (int)(arr.length/2);m++,n--){
temp = arr[m];
arr[m] = arr[n];
arr[n] = temp;
}
System.out.println(Arrays.toString(arr));
}
}