1 package shuzu;
 2 
 3 public class ShuZu {
 4     
 5     public static void main(String[] args)
 6     {        
 7                 //反转排序
 8         int arr[] = {6,7,2,9,3,5,4,1,8};
 9         
10         for(int i = 0; i < arr.length/2; i++)//两两交换,只需循环数组长度的一半
11         {
12             int temp = arr[i];//声明中间变量,进行数中组两数交换
13             arr[i] = arr[arr.length - 1 - i];
14             arr[arr.length - 1- i] = temp;
15 
16         }
17         //遍历数组输出数组元素值
18         for(int x : arr)
19         {
20             System.out.print(x);
21         }
22     }
23 
24 }        

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2021-07-26
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-17
  • 2021-05-27
  • 2022-12-23
  • 2021-09-13
  • 2022-12-23
相关资源
相似解决方案