/*
题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
*/
import java.util.*;
public class Class35 {
public static void main(String[] args) {
System.out.println("请输入数组的长度:");
Scanner sc1 = new Scanner(System.in);
//数组的长度
int n = sc1.nextInt();
System.out.println("请输入数字:");
Scanner sc2 = new Scanner(System.in);
int[] a = new int[n];
for(int i = 0; i < n; i++){
a[i] = sc2.nextInt();
}
System.out.println("输出交换前的数组:");
for(int z = 0; z < n; z++){
System.out.print(a[z] + " ");
}
System.out.println();
int max = a[0];
int index1 = 0;
int index2 = 0;
for(int j = 0; j < n; j++){
if(a[j] > max){
max = a[j];
index1 = j;
}
if(index1 != 0){
int temp1 = a[0];
a[0] = a[index1];
a[index1] = temp1;
}
int min = a[0];
for(int t = 0; t < n; t++){
if(a[t] < min){
min = a[t];
index2 = t;
}
}
if(index2 != n - 1){
int temp2 = a[n - 1];
a[n - 1] = a[index2];
a[index2] = temp2;
}
System.out.println("输出交换后的数组:");
for(int z = 0; z < n; z++){
System.out.print(a[z] + " ");
}
}
}
}