A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

对一个给定的数组进行反转。
        {23,14,88,5} ->
        {5,88,14,23}
        */
        public static void reverse(int[] arr)
        {
                for(int start=0,end=arr.length-1; start<end; start++,end--)
                {
                        swap(arr,start,end);
                }
        }

        public static void swap(int[] arr,int a,int b)
        {
                int temp = arr[a];
                arr[a] = arr[b];
                arr[b] = temp;
        }

3 个回复

倒序浏览
果断赞一个
回复 使用道具 举报
int[] newArr = new int[arr.length] ;
for(int i = arr.length - 1 ; i >= 0 ; i--){
   newArr[arr.length - 1 -i] = arr[i] ;
}
return newArr ;
回复 使用道具 举报
白月留梦 来自手机 中级黑马 2015-7-11 07:24:50
板凳
倒着打印
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马