import java.util.ArrayList;
 import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         ArrayList<String> list = new ArrayList<>();
         Scanner input = new Scanner(System.in);
         System.out.print("Enter the count of points: ");
         int pointCount = input.nextInt();
         double[][] points = new double[pointCount][2];

         System.out.print("Enter the points: ");
         for(int i = 0; i < pointCount; i++)
             for(int j = 0; j < 2; j++)
                 points[i][j] = input.nextDouble();

         input.close();

         double shortestDistance = distance(points[0][0], points[0][1], points[1][0], points[1][1]);
         double currentDistance = shortestDistance;

         for(int i = 0; i < points.length; i++)
             for(int j = i + 1; j < points.length; j++)
             {
                 currentDistance = distance(points[i][0], points[i][1], points[j][0], points[j][1]);
                 if(currentDistance < shortestDistance)
                 {
                     list.clear();
                     shortestDistance = currentDistance;
                     list.add("(" + points[i][0] + " " + points[i][1] + ") (" + points[j][0] + " " + points[j][1] + ")");
                 }
                 else if(currentDistance == shortestDistance)
                 {
                     list.add("(" + points[i][0] + " " + points[i][1] + ") (" + points[j][0] + " " + points[j][1] + ")");
                 }
             }

         System.out.println("The shortest distance is " + shortestDistance);
         for(int i = 0; i < list.size(); i++)
             System.out.println(list.get(i));
     }

     public static double distance(double x1, double y1, double x2, double y2)
     {
         double square = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
         return Math.sqrt(square);
     }
 }

HW7.8的更多相关文章

  1. HW7.18

    public class Solution { public static void main(String[] args) { int[][] m = {{1, 2}, {3, 4}, {5, 6} ...

  2. HW7.17

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  3. HW7.16

    import java.util.Arrays; public class Solution { public static void main(String[] args) { int row = ...

  4. HW7.15

    public class Solution { public static void main(String[] args) { double[][] set1 = {{1, 1}, {2, 2}, ...

  5. HW7.14

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  6. HW7.13

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  7. HW7.12

    import java.util.Scanner; public class Solution { public static void main(String[] args) { double[] ...

  8. HW7.11

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  9. HW7.10

    public class Solution { public static void main(String[] args) { int[][] array = new int[3][3]; for( ...

  10. HW7.9

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

随机推荐

  1. uva 10791

    还算比较水的一个数学题 求因子的最小和  总是用小的数去除   注意特判  是用int不行哦........ #include <cstdio> #include <cmath> ...

  2. zoj 2387

    额  一个贪心  好难想到 ...... #include <cstring> #include <cstdio> #include <algorithm> #in ...

  3. Injection Attacks-XML注入

    注入攻击 XML注入 虽然JSON的出现实现了服务器与客户端之间的"轻量级"数据交流,但是,作为另一种流行的可行方案,许多web服务API同时还是继续支持XML.另外,除了web服 ...

  4. Android 显示大图片

    主要的代码如下: BitmapFactory.Options options = new BitmapFactory.Options(); //图片解析配置 options.inJustDecodeB ...

  5. [java线段树]2015上海邀请赛 D Doom

    题意:n个数 m个询问 每个询问[l, r]的和, 再把[l, r]之间所有的数变为平方(模为9223372034707292160LL) 很明显的线段树 看到这个模(LLONG_MAX为922337 ...

  6. 213. House Robber II

    题目: Note: This is an extension of House Robber. After robbing those houses on that street, the thief ...

  7. Android 应用开发性能优化完全分析

    1 背景 其实有点不想写这篇文章的,但是又想写,有些矛盾.不想写的原因是随便上网一搜一堆关于性能的建议,感觉大家你一总结.我一总结的都说到了很多优化注意事项,但是看过这些文章后大多数存在一个问题就是只 ...

  8. Jquery attr()方法 属性赋值和属性获取

    jquery中用attr()方法来获取和设置元素属性,attr是attribute(属性)的缩写,在jQuery DOM操作中会经常用到attr(),attr()有4个表达式. 1. attr(属性名 ...

  9. 高难度(1)什么是AR

    在介绍增强现实(AR)之前,需要先说说虚拟现实(VR) 虚拟现实是从英文Virtual Reality 一词翻译过来的,简称VR.VR 技术是采用以计算机技术为核心的技术,生成逼真的视.听.触觉等一体 ...

  10. C#读取注册表信息

    注册表是视窗系统的一个核心的数据库,在这个数据库中存放中与系统相关的各种参数,这些参数直接控制中系统的启动.硬件的驱动程序安装信息以及在视窗系统上运行的各种应用程序的注册信息等.这就意味着,如果注册表 ...