题解 | #数组倒转#

数组倒转

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 l = 0 ;
    int r = arr.length-1;
          while(l < r ){
              int tmp = arr[l] ;
               arr[l] = arr[r] ;
               arr[r] = tmp;
              l++;
              r--;
          }
    System.out.println(Arrays.toString(arr));
}

}

全部评论

相关推荐

10-17 12:16
同济大学 Java
7182oat:快快放弃了然后发给我,然后让我也泡他七天最后再拒掉,狠狠羞辱他一把😋
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务