Java、最右下角的点

在计算几何中经常需要从一个点集中找到最右下角的点。编写以下方法,从一个点的集合中返回最右下角的点:
        public static double[] getRightmostLowestPoint(double[][] points)
        编写一个测试程序,提示用户输入6个点的坐标,然后显示最右下角的点。


package pack2;

import java.util.Scanner;

public class RightMostLowestPoint {	

	public static void main(String[] args) {
		rightMostLowestPoint();
	}
	
//	1.5 2.5 -3 4.5 5.6 -7 6.5 -7 8 1 10 2.5

	public static void rightMostLowestPoint() {
		try(Scanner input = new Scanner(System.in);) {
			final int COLUMN = 2;
			
			System.out.print("Enter the number of points: ");
			double[][] points = new double[input.nextInt()][COLUMN];
			
			System.out.print("Enter " + points.length + " points: ");
			inputData(input, points);
			
			double[] point = getRightMostLowestPoint(points);
			System.out.println("The rightmost lowest point is (" + point[0] + ", " 
                             + point[1] + ")");
		}
	}
	
	/**接收数据输入*/
	public static void inputData(Scanner input, double[][] points) {
		for (int i = 0; i < points.length; i++) 
			for (int j = 0; j < points[i].length; j++) 
				points[i][j] = input.nextDouble();
	}
	
	/**最右下的点*/
	public static double[] getRightMostLowestPoint(double[][] points) {
		double[] mostLowestPoint = new double[2];
		
		for (int i = 0; i < points.length; i++) 
			if((points[i][0] >= mostLowestPoint[0]) && (points[i][1] <= 
                                         mostLowestPoint[1])) {
				mostLowestPoint[0] = points[i][0];
				mostLowestPoint[1] = points[i][1];
			}
		
		return mostLowestPoint;
	}
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值