HW7.8

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的更多相关文章
- HW7.18
public class Solution { public static void main(String[] args) { int[][] m = {{1, 2}, {3, 4}, {5, 6} ...
- HW7.17
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW7.16
import java.util.Arrays; public class Solution { public static void main(String[] args) { int row = ...
- HW7.15
public class Solution { public static void main(String[] args) { double[][] set1 = {{1, 1}, {2, 2}, ...
- HW7.14
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW7.13
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW7.12
import java.util.Scanner; public class Solution { public static void main(String[] args) { double[] ...
- HW7.11
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW7.10
public class Solution { public static void main(String[] args) { int[][] array = new int[3][3]; for( ...
- HW7.9
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
随机推荐
- notepad++ 开启/关闭 记住最后打开的文件
开启记住最后打开的文件 1) 6.3以前版本如下设置: 设置-->首选项-->其他 把左下角的 "记住最后打开文件" 勾选. 2) 6.3以后版本如下设置: 设置--& ...
- DWR
DWR(Direct Web Remoting)是一个用于改善web页面与Java类交互的远程服务器端Ajax开源框架,可以帮助开发人员开发包含AJAX技术的网站.它可以允许在浏览器里的代码使用运行在 ...
- http://blog.csdn.net/xyang81/article/details/7292380
http://blog.csdn.net/xyang81/article/details/7292380
- hhtml from表单为什么能提交数据
1.html的列表,分为list,table,form. form表单是专门用来提交数据的,即上传数据的.所以form表单默认是必须有提交按钮的,也就是必须要有个button type类型为submi ...
- (原创)CityEngine 2014和ArcGIS 10.3冲突问题的解决
先卸载ArcGIS License Manager 10.3 安装ArcGIS License Manager 10.2.2 用keygen算出ArcGIS 10.3的许可,似乎本许可在ArcGI ...
- SGU111 Very simple problem
多少个平方数小于等于X,二分. PS:java BigInteger. import java.util.*; import java.math.*; public class Solution { ...
- Android 设定activity的进入和退出效果
看了android的源代码和资源文件,终于明白如何去修改设置Dialog和Activity的进入和退出效果了.设置Dialog首先通过 getWindow()方法获取它的窗口,然后通过getAttri ...
- 搜索引擎spam
什么是SPAM?搜索引擎优化中的SPAM 在搜索引擎优化相关的文章中中经常遇到“SPAM”一词,SPAM通常用来指垃圾邮件,不过在搜索引擎营销中所说的SPAM是专门针对那些欺骗搜索引擎的信息.搜索引擎 ...
- UEFI GPT
其实关于UEFI的几篇文章很早就写下了,只是自己读了一遍感觉很不满意,就决定重写.目的是想用最简单直白的语言把内容写出来,让每个人都能轻松读懂.当然,如果你已经对这些内容有了很深的理解的话,这篇文章除 ...
- [LOJ 1248] Dice (III)
G - Dice (III) Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Descri ...