Java黑皮书课后题第8章:*8.8(所有最近的点对)修改程序清单8-3,找出所有所有具有最小距离的点对。下面是一个运行示例

博客探讨了Java算法问题,具体是修改程序清单8-3以找出所有具有最小距离的点对。内容包括题目描述、运行示例、破题思路及代码实现,重点在于如何在已知最短距离的情况下遍历并输出符合条件的点对。
摘要由CSDN通过智能技术生成

*8.8(所有最近的点对)修改程序清单8-3,找出所有所有具有最小距离的点对。下面是一个运行示例

题目

题目描述与运行示例

*8.8(所有最近的点对)修改程序清单8-3,找出所有所有具有最小距离的点对。下面是一个运行示例:

Enter the number of points: 8
Enter 8 points: 0 0 1 1 -1 -1 2 2 -2 -2 -3 -3 -4 -4 5 5
The closest two points are (0.0, 0.0) and (1.0, 1.0)
The closest two points are (0.0, 0.0) and (-1.0, -1.0)
The closest two points are (1.0, 1.0) and (2.0, 2.0)
The closest two points are (-1.0, -1.0) and (-2.0, -2.0)
The closest two points are (-2.0, -2.0) and (-3.0, -3.0)
The closest two points are (-3.0, -3.0) and (-4.0, -4.0)
Their distance is 1.4142135623730951

程序清单8-3

import java.util.Scanner;

public class qingdan {
   
    public static void main(String[] args) {
   
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the number of points: ");
        int numberOfPoints = input.nextInt();

        // Create an array to store points
        double[]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值