知识点
绘点
随机函数
题目
1.1.31 随机连接。编写一段程序,从命令行接受一个整数 N 和 double 值 p(0 到 1 之间)作为参数, 在一个圆上画出大小为 0.05 且间距相等的 N 个点,然后将每对点按照概率 p 用灰线连接。
1.1.31 Random connections. Write a program that takes as command-line arguments an integer N and a double value p (between 0 and 1), plots N equally spaced dots of size .05 on the circumference of a circle, and then, with probability p for each pair of points, draws a gray line connecting them.
分析
这道题考察了Random库和StdDraw库的使用
StdRandom.uniform()方法生成0到1之间的数;
StdDraw.point(0.5, 0.5)方法可以生成居中的点
举例,代码
//设置画笔颜色
StdDraw.setPenColor(StdDraw.RED);
//设置画笔的大小(即直径)
StdDraw.setPenRadius(0.5);
//画个点
StdDraw.point(0.5, 0.5);
的效果如下