import java.util.Arrays; import java.util.Random; public class bulubulu { public static void main(String[] args) { int[] ints = new int[18]; for (int i = 0; i < ints.length ; i++) { ints[i]=new Random().nextInt(100); } pp(ints); } public static void pp(int[] ints){ boolean b = true; for (int i = 0; i < ints.length ; i++) { for (int j = 0; j < ints.length-i-1 ; j++) { if (ints[j]>ints[j+1]){ int a = ints[j]; ints[j]=ints[j+1]; ints[j+1]=a; b = false; } } if (b){ break; }else{ b=true; } } System.out.println(Arrays.toString(ints)); } }
冒泡排序,(优化)
最新推荐文章于 2023-02-20 22:43:42 发布