import java.util.concurrent.ThreadLocalRandom; public class T1 { public static void main(String[] args) { int[] arr = new int[10]; ThreadLocalRandom r = ThreadLocalRandom.current(); for (int i = 0; i < arr.length; i++) { arr[i] = r.nextInt(100); } for (int tmp : arr) System.out.print(tmp + "\t"); System.out.println(); for (int k = 1; k < arr.length; k++) { for (int i = 0; i < arr.length - k; i++) { if (arr[i] > arr[i + 1]) { int tmp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = tmp; } } } for (int tmp :arr) System.out.print(tmp+"\t"); } }
简单的 冒泡排序
最新推荐文章于 2024-11-03 11:01:20 发布