Click here to Skip to main content
15,796,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 19-Oct-12 21:50pm
v4

1 solution

Java
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.
 
Share this answer
 
v3
Comments
javamontrealman 20-Oct-12 2:19am    
complier says cannot find symbol for numbers.length. I don't really get whats wrong, isn't that just the number of elements in the array?
Zoltán Zörgő 20-Oct-12 2:41am    
Oh, sorry, copy-paste - see update!
javamontrealman 20-Oct-12 2:49am    
THANK YOU SO MUCH!!!!
Rawaa Haider 10-Dec-21 18:03pm    
Can I get this code after corrected?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900