📄 00404ee41167001b1fc8c86c12fb3d87
字号:
package distance;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.Math;
import java.util.Random;
public class ProducingPoints {
/*get the 2^n points by inputing a number on console */
public int getNumOfPoints() throws NumberFormatException, IOException{
System.out.println("pls input the value of n:");
/*用 BufferedReader 包装 System.in,以便更方便的读取输入*/
/*主要是为了使用 readLine() 方法来读取*/
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
/*get the 2^n points*/
int NumberOfPoints= (int) Math.pow(2,Integer.parseInt(reader.readLine().trim()));
System.out.println("2^n:" + NumberOfPoints);
return NumberOfPoints;
}
/*initialize the array of points.
* every coordinate is between 1 and 10*/
public Point[] getPoints(int NumOfPoints){
Point[] PointSet= new Point[NumOfPoints];
for(int i = 0;i < NumOfPoints;i++){
Random RandomNum = new Random();
double rn = 10*RandomNum.nextDouble();
if(rn < 1)
rn += 1;
if(i != 0 && rn < PointSet[i - 1].getXCoordinate())
rn = (PointSet[i - 1].getXCoordinate() + RandomNum.nextDouble());
PointSet[i] = new Point();
PointSet[i].setXCoordinate(rn);
PointSet[i].setYCoordinate(10*RandomNum.nextDouble());
}
return PointSet;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -