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 ...
随机推荐
- CSS文件和Javascript文件的压缩
像JQuery一样来压缩我们的CSS和JS 我们都知道一般JQuery新版本发布的时候往往会有几个不同类型文件,比如原始版本文件.最小文件以及其他配合IDE智能提示的各种版本文件,前期我们使用JQue ...
- scikit-learn安装
1.依赖包: Cython.rose.numpy.scipy.lapack.atlas http://blog.chinaunix.net/uid-22488454-id-3978860.html
- c++: 获取delete[]中的数组大小
看一个小例子: 1 #include <iostream> 2 3 using namespace std; 4 5 class A { 6 public: 7 A() { ...
- PowerDesigner将name自动添加到Comment注释的方法 VB代码
Option Explicit ValidationMode = True InteractiveMode = im_Batch Dim mdl ' the current model ' get t ...
- C/C++语言参数传递----函数/方法 参数的指针引用传递
int m_value = 1; void func(int *p) { p = &m_value; } int main(int argc, char *argv[]) { int n = ...
- redis面试
1. 使用Redis有哪些好处? (1) 速度快,因为数据存在内存中,类似于HashMap,HashMap的优势就是查找和操作的时间复杂度都是O(1) (2) 支持丰富数据类型,支持string,li ...
- HeadFirst设计模式之模板方法模式
一. 1.The Template Method defines the steps of an algorithm and allows subclasses to provide the impl ...
- Android:@id和@+id
@id代表引用已有的id,而@+id是新增加一个id 如果使用@+id/name形式,当R.java中存在名为name变量时,则该组件会使用该变量的值作为标识.如果不存在该变量,则添加一个新的变量,并 ...
- eclipse中的输入提示怎么设置
对于大多数的开发人员来说,打代码是一件非常繁琐的事情,eclipse中为我们提供了自动提示的功能,但是默认的提示只有当我们输入小数点后才能出现提示框,那么我们如何设置eclipse,能够让它为我们提示 ...
- SQL 2008 R2 启动失败 提示 请求失败或服务未及时响应
为什么启动sql server 配置管理器出现请求失败或服务未及时响应_百度知道 http://zhidao.baidu.com/link?url=ElemzIan6I2CqJsd7-7uk5TV25 ...