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 11143

    #include<cstdio> #include<cstring> #include<algorithm> #define maxn 5100 #include& ...

  2. uva 10069

    简单的dp 但是一个大数加法  套用了末位大牛的类模板 #include <cstdio> #include <cstring> #include <algorithm& ...

  3. 学习笔记:shared_ptr陷阱

    条款1:不要把一个原生指针给多个shared_ptr管理 int* ptr = new int; shared_ptr<int> p1(ptr); shared_ptr<int> ...

  4. SQL Server CONVERT() 函数

    http://www.w3school.com.cn/sql/func_convert.asp 定义和用法 CONVERT() 函数是把日期转换为新数据类型的通用函数. CONVERT() 函数可以用 ...

  5. POJ 1797 Heavy Transportation(Dijkstra)

    http://poj.org/problem?id=1797 题意 :给出N个城市M条边,每条边都有容量值,求一条运输路线使城市1到N的运输量最大. 思路 :用dijkstra对松弛条件进行变形.解释 ...

  6. MyBatis-Spring 执行SQL语句的流程

    1. 从SqlSessionDaoSupport开始 通常我们使用MyBatis会让自己的DAO继承SqlSessionDaoSupport,那么SqlSessionDaoSupport是如何运作的呢 ...

  7. !! Scrum之 流程和术语

    !!Scrum之 流程和术语 http://www.cnblogs.com/zhoujg/archive/2009/07/15/1523680.html 以下将对一些术语进行简单介绍,以便大家现在开始 ...

  8. 【HDOJ】4363 Draw and paint

    看题解解的.将着色方案映射为40*40*5*5*5*5*2个状态,40*40表示n*m,5*5*5*5表示上下左右相邻块的颜色,0表示未着色.2表示横切或者竖切.基本思路是记忆化搜索然后去重,关键点是 ...

  9. Java数据库增删改查

    数据库为MySQL数据库,Oracle数据库类似: create database db_test;--创建数据库 ';--创建用户 grant all privileges on db_test.* ...

  10. grep 同时满足多个关键字和满足任意关键字

    grep 同时满足多个关键字和满足任意关键字 ① grep -E "word1|word2|word3"   file.txt    满足任意条件(word1.word2和word ...