public static double manhattanDistance(double[] p,double[] q){
  double ret=0;
  for (int i=0; i < p.length; i++) {
    double difference=p[i] - q[i];
    ret+=Math.abs(difference);
  }
  return ret;
}

public static double manhattanDistance ( double [ ] p , double [ ] q ) { double ret = 0 ; for ( int i = 0 ; i < p . length ; i ++ ) { double difference = p [ i ] - q [ i ] ; ret += Math . abs ( difference ) ; } return ret ; }
this will calculate the manhattan distance between two sets of points . the manhattan distance is equivalent to : 1_sum_n | p_i - q_i |
