public static void sort() { List<Integer> list = new ArrayList<>(); Scanner sc = new Scanner(System.in); while (sc.hasNextInt()){ list.add(sc.nextInt()); } int temp; Integer [] xxx = list.stream().toArray(Integer[]::new); for (int i = 0; i < xxx.length-1; i++) { for (int j = 0; j < xxx.length-i-1; j++) { if(xxx[j]>xxx[j+1]){ temp=xxx[j+1]; xxx[j+1]=xxx[j]; xxx[j]=temp; } } } // Collections.sort(list); System.out.println(xxx); for (int i = 0; i < xxx.length; i++) { System.out.print(xxx[i]+"/"); } sc.close(); }
冒泡排序代码
于 2022-09-28 16:17:50 首次发布