//选择法排序 import java.util.Scanner; class Sort { public static void main(String[] args) { int n; Scanner scan = new Scanner(System.in); System.out.println("请输入一个十进制的整数:"); n = scan.nextInt(); int[] arr = new int[n]; System.out.println("请输入"+n+"个十进制的整数:"); for(int x = 0;x<arr.length;x++){ arr[x] = scan.nextInt(); } sort(arr,arr.length); System.out.println(); System.out.println("输出排序之后的数组的元素:"); for(int i = 0;i<arr.length;i++){ System.out.print(arr[i]+"\t"); } } public static void sort(int[] a,int n){ int t=0,k=0,i,j; for(i=0;i<a.length-1;i++){ k = i; for(j=i+1;j<a.length;j++){ if(a[j]<a[k]){ k = j; } } if(k!=i){ t = a[k]; a[k] = a[i]; a[i] = t; } } } }