import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int cNumber = scanner.nextInt(); List<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < cNumber; i++) { list.add(scanner.nextInt()); } Collections.sort(list); String replace = list.toString().replaceAll("[\\[\\],]",""); System.out.println(replace); } }
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { //数组排序 Scanner scanner = new Scanner(System.in); int cNumber = scanner.nextInt(); int nums[] = new int[cNumber]; for (int i = 0; i < cNumber; i++) { nums[i]=scanner.nextInt(); } Arrays.sort(nums); for (int i = 0; i < nums.length; i++) { System.out.print(nums[i]+" "); } } }
import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int cNumber = scanner.nextInt(); List<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < cNumber; i++) { list.add(scanner.nextInt()); } list.sort(new Comparator<Integer>() { @Override public int compare(Integer arg0, Integer arg1) { return Integer.compare(arg0, arg1); } }); String replace = list.toString().replace("[", ""); String replace2 = replace.replace("]", ""); String replace3 = replace2.replace(",", ""); System.out.println(replace3); } }
原文地址:https://www.cnblogs.com/wzqjy/p/8280579.html
时间: 2024-10-14 00:41:18