//冒泡法排序。 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; for(int i = 0;i<a.length;i++){ for(int j = 0;j<a.length-1-i;j++){ if(a[j] > a[j+1]){ t = a[j]; a[j] = a[j+1]; a[j+1] = t; } } } } }