HW7.7

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的更多相关文章
- 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 ...
随机推荐
- SGU 186
总是拆最短的链子 连接长的链子 贪心.... #include <cstdio> #include <cstring> #include <cmath> #i ...
- python检测文件是否更新
import os import time filename = "test.txt" info = os.stat(filename) if time.time()-info.s ...
- Tornado,了解一下
多了解不一样的PYTHON框架,对深入了解DJANGO,总是有帮助的. import textwrap import tornado.httpserver import tornado.ioloop ...
- http://jingyan.baidu.com/article/e4511cf33479812b855eaf67.html
http://jingyan.baidu.com/article/e4511cf33479812b855eaf67.html
- Android ExpandableListView 带有Checkbox的简单应用
expandablelistview2_groups.xml <?xml version="1.0" encoding="utf-8"?> < ...
- C语言 结构体的内存对齐问题与位域
http://blog.csdn.net/xing_hao/article/details/6678048 一.内存对齐 许多计算机系统对基本类型数据在内存中存放的位置有限制,它们会要求这些数据的首地 ...
- Java 的 Class Path 和 Package
前言: 由于这两个问题新手问得较多, 且回答比较零散, 很难统一整理, 所以就直接写了一篇, 还请大家见谅. 正文:一, 类路径 (class path) 当你满怀着希望安装好了 java, ...
- Android:布局实例之常见用户设置界面
实现效果: 整理思路: 1.控件:文字TextView 和 右箭头ImageView 2.因为考虑到点击效果,设计为:最外层为全圆角,内层有四种情况,分别为上圆角.无圆角.下圆角和全圆角. 3.内层样 ...
- 安装Ubuntu双系统系列——为Firefox安装Adobe Flash Player
使用环境:OS:Ubuntu 12.04 LTSBrowser: Firefox 12.0Adobe Flash Player: install_flash_player_11_linux.x86_6 ...
- Octave下载
发福利啦,今天下了半天Octave都没下载下来,最后让一个香港的同学帮忙下好传过来的....放到网盘里造福大家 GNU_Octave_3.8.0-6.dmg 链接: http://pan.baidu. ...