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. POJ2524+并查集

    题意简单. 询问n个人的宗教关系. #include<stdio.h> ; int fa[ maxn ]; int vis[ maxn ]; void init( int n ){ ;i& ...

  2. iOS中关于KVC与KVO知识点

    iOS中关于KVC与KVO知识点 iOS中关于KVC与KVO知识点  一.简介 KVC/KVO是观察者模式的一种实现,在Cocoa中是以被万物之源NSObject类实现的NSKeyValueCodin ...

  3. png24是支持Alpha透明的。。。。。。

    这个可能跟每个人使用切图软件有关. 1.Photoshop   1)只能导出布尔透明(全透明或者全不透明)的PNG8.    2)能导出alpha透明(全透明,全不透明,半透明)的PNG24.     ...

  4. HeadFirst设计模式之策略模式

    什么是策略模式:它定义了一系列算法,可以根据不同的实现调用不同的算法 大多数的设计模式都是为了解决系统中变化部分的问题 一.OO基础 抽象.封装.多态.继承 二.OO原则 1.封装变化,如把FlyBe ...

  5. matlab 中保存某几个变量

    save  AOA.mat dingjiao RMSE%保存变量dingjiao,RMSE于AOA.mat clear all;%当删除所有数据之后 load AOA.mat%还可以读出这两个变量的数 ...

  6. linux应用程序问题

    ---- 1 ----

  7. Android开发之错误:elicpse运行时弹出Running Android Lint has encountered a problem failed, nullpointerexception

    昨天安装了下Android Studio,把SDK路径指向了ADT目录下的SDK目录.同时FQ出去更新了下SDK.然后今天运行eclipse的时候,弹出错误,同时在工程的名称处有错误提醒,但是代码中没 ...

  8. zoj 3351 Bloodsucker(概率 dp)

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4530 dp[i]表示现在存在i个吸血鬼要达成目标(全为吸血鬼)天数的数学 ...

  9. .net 测试工具类

    fluentassertions QuickStart  (替换Assert ) https://github.com/dennisdoomen/fluentassertions/wiki   Moq ...

  10. [原]Unity3D深入浅出 - 摄像机组件(Camera)

    在Unity中创建一个Camera后,除了默认带一个Transform组件外,还会附带Flare Layer.GUI Layer.Audio Listener等4个组件,如下图. ClearFlags ...