ex28.java
来自「JAVA 编程思想 第四版 课后习题答案 代码全!」· Java 代码 · 共 18 行
JAVA
18 行
// holding/Ex28.java
// TIJ4 Chapter Holding, Exercise 28, page 427
/* Fill a PriorityQueue (using offer()) with Double values created using
* java.util.Random, then remove the elements using poll() and display them.
*/
import java.util.*;
public class Ex28 {
public static void main(String[] args) {
Random rand = new Random();
PriorityQueue<Double> d = new PriorityQueue<Double>();
for(int i = 0; i < 10; i++)
d.offer(rand.nextDouble() * i);
while(d.peek() != null)
System.out.print(d.poll() + " ");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?