Java欧几里得距离代码 [英] Java Euclidean distance code

查看:89
本文介绍了Java欧几里得距离代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写我的代码的这一部分,以便它可以计算两个未知数组之间的欧几里得距离,但不适用于编译器.有人可以告诉我怎么了.谢谢.

I am writing this part of my code so that it can calculate the Euclidean distance between two unknown arrays, but it is not working with the complier. Could someone tell me what is wrong. Thanks.

推荐答案

public static double calculateDistance(double[] array1, double[] array2)
    {
        double Sum = 0.0;
        for(int i=0;i<array1.length;i++) {
           Sum = Sum + Math.pow((array1[i]-array2[i]),2.0);
        }
        return Math.sqrt(Sum);
    }



您有语法和语义错误.
确保两个数组具有相同数量的元素.



You had syntactic and semantic errors.
Make sure, that both arrays have same number of elements.


这篇关于Java欧几里得距离代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆