package shiyan3; import java.util.Arrays; public class shiyan3_1 { public static void main(String args[]) { int a[] = {6, 8, 9, 10, 36, 25, 8, 2, 6, 7, 9,}; int N = a.length; int t= 0; int minIndex = -1; for (int i = 0; i < N - 1; i++) { minIndex = i; t=i; for (int j = i + 1; j <= N - 1; j++) { if (a[j]<a[minIndex]){ minIndex = j; } } if(minIndex!= i){ int temp = a[i]; a[i]= a[minIndex]; a[minIndex]= temp; } } System.out.println("数组最小的是"+a[0]); System.out.println("数组最大的是"+a[t+1]); } }