Originally Posted by
smith999
...
... how would I ...
I don't get much out of the statement about Euclidean distance, so I'll try to express it in a way that makes sense to me.
In words: The Euclidean distance between two numerical arrays of equal length is equal to the square root of the sum of the squares of the differences between corresponding array elements.
It's actually easier to do than it is to talk about, and pseudo-code may be more clear than my words.
Anyhow...
See whether you think the following few lines of pseudo-code make sense according to the definition of Euclidean distance. If the pseudo-code makes sense, then implementation with Java is a snap. If it doesn't make sense to you, then you must think about it until it does!
(Just kidding. If there are questions, it's always OK to ask. But think about it first.)
This assumes that the two arrays are the same length, as your assignment stipulates.
Declare a double precision variable, sumSquares. Initialize sumSquares to 0.0;
Repeat the following loop for integer values of k from 0 through the index of the last element of the arrays:
BEGIN LOOP
Add the square of (array1[k]-array2[k]) to sumSquares
END LOOP
Then take the square root of sumSquares. That's the Euclidean distance between the two arrays
Taa-Daa!
Cheers!
Z