import java.sql.SQLOutput; import java.util.Arrays; import java.util.Scanner; //冒泡排序 public class test { public static void main(String[] args) { int[] a = {5,4,6,8,9,1,7,2,3} ; int array[] = sort(a); System.out.println(Arrays.toString(array)); } public static int[] sort(int[] a){ for (int i = 0; i < a.length-1; i++) {//第一层循环用于限制循环次数 for(int j = 0; j < a.length-1-i; j++){//第二层循环用于限制比较次数 if(a[j+1]>a[j]){ int temp = a[j+1]; a[j+1] = a[j]; a[j] = temp; } } } return a; } }
标签:java,int,冒泡排序,static,import,public From: https://www.cnblogs.com/muzhaodi/p/18004101