code: public static double mad(int[] x) {
          int m = median(x);
          for (int i = 0; i < x.length; i++) {
              x[i] = Math.abs(x[i] - m);
          }
  
          return median(x);
      }
docs: Returns the median absolute deviation (MAD). Note that input array will
  be altered after the computation. MAD is a robust measure of
  the variability of a univariate sample of quantitative data. For a
  univariate data set X<sub>1</sub>, X<sub>2</sub>, ..., X<sub>n</sub>,
  the MAD is defined as the median of the absolute deviations from the data's median:
  <p>
  MAD(X) = median(|X<sub>i</sub> - median(X<sub>i</sub>)|)
  <p>
  that is, starting with the residuals (deviations) from the data's median,
  the MAD is the median of their absolute values.
  <p>
  MAD is a more robust estimator of scale than the sample variance or
  standard deviation. For instance, MAD is more resilient to outliers in
  a data set than the standard deviation. It thus behaves better with
  distributions without a mean or variance, such as the Cauchy distribution.
  <p>
  In order to use the MAD as a consistent estimator for the estimation of
  the standard deviation &sigma;, one takes &sigma; = K * MAD, where K is
  a constant scale factor, which depends on the distribution. For normally
  distributed data K is taken to be 1.4826. Other distributions behave
  differently: for example for large samples from a uniform continuous
  distribution, this factor is about 1.1547.