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 ...
随机推荐
- YUV格式详解
What is YUV YUV,是一种颜色编码方法. YUV是编译true-color颜色空间(color space)的种类,Y'UV, YUV, YCbCr,YPbPr等专有名词都可以称为YUV, ...
- 分析java程序中cpu占用过高的线程
http://blog.csdn.net/jgwei/article/details/12079147 http://hllvm.group.iteye.com/group/topic/38893 h ...
- Codeforces Round #243 (Div. 2) A~C
题目链接 A. Sereja and Mugs time limit per test:1 secondmemory limit per test:256 megabytesinput:standar ...
- ubuntu 和 win7 远程登陆 + vnc登陆
ubuntu 和 win7 远程登陆: 第一种(通过win7自带的远程桌面来连接ubuntu) 1. windows7配置 我的电脑->属性->远程设置.-----允许远程连接 2. ub ...
- google maps v3 添加自定义图标(marker,overlay)
google搜了很久都没找到符合v3版本的google maps自定义图标,可以让图标使用自己的html,都是V2版本的,依靠重写google api属性来完成. 然后就找了个jquery下的goog ...
- Android 九宫格密码锁进入程序
设置九宫格密码锁进入程序,设置,重置,取消等,安卓巴士地址http://www.apkbus.com/forum.php?mod=viewthread&tid=182620&extra ...
- Android 内核初识(2)android系统架构
以模块角度 以Java,native,kernel角度
- 摄像头(4)用Camera和SurfaceView自定义拍照程序
定制拍照程序的基本步骤 1,打开照相机:Camera.open 这是独占方式打开的 2,创建SurfaceView对象 多缓冲,多线程view 3,添加回调事件监听器(SurfaceHolder.ad ...
- Eclipse导入项目
导入Eclipse项目 File->Import...->Existing Projects into Workspace->Next->Browse...->Finis ...
- 查询json数据结构的8种方式
查询json数据结构的8种方式 你有没有对“在复杂的JSON数据结构中查找匹配内容”而烦恼.这里有8种不同的方式可以做到: JsonSQL JsonSQL实现了使用SQL select语句在json数 ...