public class Solution
 {
     public static void main(String[] args)
     {
         double[][] points =
         {
             {-1, 0, 3}, {-1, -1, -1},
             {4, 1, 1}, {2, 0.5, 9},
             {3.5, 2, -1}, {3, 1.5, 3},
             {-1.5, 4, 2}, {5.5, 4, -0.5}
         };

         double shortestDistance = distance(points[0][0], points[0][1], points[0][2],
             points[1][0], points[1][1], points[1][2]);
         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[i][2],
                     points[j][0], points[j][1], points[j][2]);
                 if(currentDistance < shortestDistance)
                     shortestDistance = currentDistance;
             }
         }

         System.out.println("The shortest distance is " + shortestDistance);
     }

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

HW7.7的更多相关文章

  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. SDK更新问题解决

    更新C:\WINDOWS\system32\drivers\etc\host文件百试不爽 第一步 打开SDK Manager下Tools->Options,选中“Force https://… ...

  2. 从List[Future[T]]到Future[List[T]]

    在课程<Principles Of Reactive Programming>里Week3的一节 "Promises, promises, promises"中,Eri ...

  3. 如何在Ubuntu下搭建Android NDK开发环境

    1 搭建Android SDK开发环境 参考在在Ubuntu下搭建Android SDK开发环境(图文)首先在Ubuntu下搭建Android SDK开发环境. 2 下载NDK开发包 打开官网: ht ...

  4. python检测文件是否更新

    import os import time filename = "test.txt" info = os.stat(filename) if time.time()-info.s ...

  5. eclipse进行开发

    最近在用eclipse进行开发的时候遇到了一个很奇怪的问题,其实这个问题很早以前就遇到了只是苦于一直没有需找到答案.直到今天又遇到了,才觉得这真是个很实用很使用的功能,所以分享给大家,希望对大家有帮助 ...

  6. lib和dll文件的区别和联系

    什么是lib文件,lib和dll的关系如何 (2008-04-18 19:44:37)    (1)lib是编译时需要的,dll是运行时需要的. 如果要完成源代码的编译,有lib就够了. 如果也使动态 ...

  7. NEERC 2014, Eastern subregional contest

    最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...

  8. codeforces #310 div1 E

    算得上是比较水的E题了吧,自己想了想写了写居然1A了 对于这道题,我们很容易想到对于原图的一个边双,定向后任意两点间一定可达 那么我们可以求出原图的边双并将每个边双缩成一个点 那么原图就变成了无环的无 ...

  9. [itint5]树中最大路径和

    http://www.itint5.com/oj/#13 要注意,一是空路径也可以,所以最小是0.然后要时刻注意路径顶多有两条子路径+根节点组成,所以更新全局最值时和返回上一级的值要注意分清. #in ...

  10. 【Mysql进阶技巧(1)】 MySQL的多表关联与自连接

    自连接 测试数据准备 CREATE TABLE `t2` ( `id` int(11) NOT NULL, `gid` char(1) DEFAULT NULL, `col1` int(11) DEF ...