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

📄 d094dd386466001b1fe3ad9a55af56f7

📁 在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 {
	
    private int NumberOfPoints ;
    
    /*get the 2^n points by inputing a number on console */
    public int getNumOfPoints() throws NumberFormatException, IOException{
    	/*用 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()));
		return NumberOfPoints;    	
    }
    /*initialize the array of points.
     * every coordinate is between 1 and 10*/
    public Point[] getPoints(){
    	Point[] PointSet= new Point[NumberOfPoints];
    	for(int i = 0;i < this.NumberOfPoints;i++){
    		/*use flay to indicate x or y coordinate to initialize
    		 * when flag = 0 to initialize x coordinate
    		 * when flag = 1 to initialize y coordinate*/
    		int flag = 0;
    		while(NumberOfPoints > 0){
    			double RandomNum = 10*(new Random()).nextDouble();
    			if(RandomNum < 1){    				
    				continue;
    			}else if(flag == 0){
    				if(i != 0 && RandomNum > PointSet[i - 1].getXCoordinate()){
    					PointSet[i].setXCoordinate(RandomNum);  
                		flag = 1;
    				}
    				else if(i == 0){
    					PointSet[i].setXCoordinate(RandomNum);  
                		flag = 1;
    				}
    				else continue;
    			}else if(flag == 1){
    				PointSet[i].setYCoordinate(RandomNum);
    			}
    			break;        		
    		}  		     		
    	}
		return PointSet;    	
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -