package com.heima.sida;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.event.TreeSelectionEvent;
public class Test05 {
public static void main(String[] args) {
int[] arr={2,1,5,3,4,8,7,9,3,35,6,4}; //测试数组
tran(arr);
for (int i : arr) {
System.out.print(i+" ");
}
}
public static void tran(int[] arr) {
// TODO Auto-generated method stub
ArrayList<Integer> al=new ArrayList<>();
for (int i : arr) {
al.add(i);
}
Collections.sort(al);
for (int i = 0; i < arr.length; i++) {
if(al.get(al.size()-1) ==arr[i]){
int b;
b=arr[i];
arr[i]=arr[0];
arr[0]=b;
}
if(al.get(0) == arr[i]){
int b;
b=arr[i];
arr[i]=arr[arr.length-1];
arr[arr.length-1]=b;
}
}
}
} |