- class Demo{
- public static void main(String[] args){
- int[] score=new int[10];
- for (int i=0;i<score.length;i++){
- score[i]=i;
- }
- print(score);
- reverseArray(score);
- System.out.println("反转后的数组:");
- print(score);
-
- }
- private static void reverseArray(int[] arr){
-
- for (int start=0,end=arr.length-1;start<end;start++,end-- ){
- int temp = arr[start];
- arr[start] = arr[end];
- arr[end] = temp;
- }
- }
- public static void print(int[] arr){
- for (int i=0;i<arr.length ;i++ ){
- System.out.print(arr[i]+(i==9?"":","));
- }
- System.out.println();
- }
- }
复制代码 |