code: public static double var(int[] x) {
          if (x.length < 2) {
              throw new IllegalArgumentException("Array length is less than 2.");
          }
  
          double sum = 0.0;
          double sumsq = 0.0;
          for (int xi : x) {
              sum += xi;
              sumsq += xi * xi;
          }
  
          int n = x.length - 1;
          return sumsq / n - (sum / x.length) * (sum / n);
      }
docs: Returns the variance of an array.