import java.util.Scanner; import java.util.Arrays; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = input.nextInt(); } Arrays.sort(nums); for (int i = 0; i < n; i++) { System.out.print(nums[i] + " "); } } }修改这段代码,使其每个元素之间用一个空格隔开,但是最后一个元素后面没有空格
时间: 2023-05-28 12:06:27 浏览: 75
java代码-import java.util.Scanner;
import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = input.nextInt();
}
Arrays.sort(nums);
for (int i = 0; i < n; i++) {
System.out.print(nums[i]);
if (i != n - 1) {
System.out.print(" ");
}
}
}
}
阅读全文