⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 00404ee41167001b1fc8c86c12fb3d87

📁 在eclipse下开发的求平面上两点之间的最短距离。通过随机在平面上生成无数个点
💻
字号:
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 + -