public long distance2 ( int [ ] point1 , int [ ] point2 ) throws Exception { if ( point1 . length == point2 . length ) { long sum = 0 ; for ( int i = 0 ; i < point1 . length ; i ++ ) { sum = sum + ( point2 [ i ] - point1 [ i ] ) * ( point2 [ i ] - point1 [ i ] ) ; } return sum ; } else { throw new Exception ( "Exception in Euclidean distance: array lengths are not equal" ) ; } }
Calculates the square of the Euclidean distance between two multidimensional points represented by integer vectors .