Java数组倒序输出:排序后逆序存储方法详解
Java数组倒序输出?
1.反转数组的方法有很多种,比如先排序,然后倒序存储
publicstaticvoidmain(String[]args){int[]nums={1,3,5,7,9,11,13,15,17,19};System.out.print("原始数组:");for(intnum:nums){System.out.print(num+"");}System.out.print("\n逆序新建数组:");for(intnum:reverseArray1(nums)){System.out.print(num+"");}}
//1排序publicstaticint[]reverseArray1(int[]nums){Arrays.sort(nums);int[]reNums=newint[nums.length];for(inti=0;i //2内置数组倒序publicstaticint[]reverseArray2(int[]nums){ArrayListjava任给一整数,将其逆序输出,如5430—》345,122345—》543221