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. sequel 连接不上,命令行能连上

    Sequel pro won't connect anymore I'm running into some trouble right now. I worked yesterday on my d ...

  2. 让wordpress分类和标签的描述支持HTML代码

    默认 WordPress 后台分类和标签的编辑页面,分类和标签的描述是不支持 HTML 代码的,我们可以通过在当前主题的 functions.php 文件添加如下代码让分类和标签的描述支持 HTML ...

  3. 1964-NP

    描述 Problems in Computer Science are often classified as belonging to a certain class of problems (e. ...

  4. BZOJ 2806 cheat

    首先这个题目显然是要二分转换成判断可行性的 之后我们考虑DP 设f(i)表示 1->i 熟悉的子串的长度的最大值 那么对于i这个点,要么不在熟悉的子串中,要么在熟悉的子串中 所以得到 f(i)= ...

  5. IIS8报错 403 404

    当IIS报403错误,而打开目录浏览权限后,又出404错误,这种错误很可能是.net的版本安装问题 注意勾选上asp.net4.5

  6. C# List中写出LINQ类似SQL的语句

    很多时候,从一个关系表中挑出一个我们需要的元素列表采用SQL语句是再容易不过的了,其实C#的List中也可以采用类似的方法,虽然List中集成了Select(), Where()等语句,不过如果你的判 ...

  7. freemarker得到数组的长度

    取得list的长度:${fields?size}.用?size不是用?length,代码如下所示: <#list properties as item> <#assign layer ...

  8. Webapp meta标签解决移动缩放的问题

    webapp开发初期,会碰到在pc端开发好的页面在移动端显示过大的问题,这里需要在html head中加入meta标签来控制缩放 <meta name=" viewport" ...

  9. C# 判断两张图片是否一致的快速方法

    #region 判断图片是否一致 /// <summary> /// 判断图片是否一致 /// </summary> /// <param name="img& ...

  10. 【转】UINavigationBar 使用总结

    原文网址:http://www.jianshu.com/p/f0d3df54baa6 UINavigationBar是我们在开发过程中经常要用到的一个控件,下面我会为大家介绍一些常用的用法. 1. 设 ...