【发布时间】:2020-04-15 18:59:36
【问题描述】:
public class StreamingIntegers {
public static void main(String[] args) {
Scanner scanin = new Scanner(System.in);
PriorityQueue<Integer> sorted_num = new PriorityQueue<>();
while (true) {
String numbers = scanin.nextLine();
if (numbers.equals("END")) {
break;
} else {
String[] tokens = numbers.split(" ");
for (String token : tokens) {
sorted_num.add(Integer.parseInt(token));
}
}
}
while (!sorted_num.isEmpty()) {
System.out.print(sorted_num.remove() + " ");
}
scanin.close();
}
}
我怎样才能去掉最后的那个小空白?
【问题讨论】:
-
请使用文字而不是图片。输出可以粘贴到问题中并像代码一样格式化。
-
习惯上接受你最喜欢的答案