code: public static int bins(double[] x, double h) {
          if (h <= 0.0) {
              throw new IllegalArgumentException("Invalid bin width: " + h);
          }
          
          double max = Math.max(x);
          double min = Math.min(x);
          
          return (int) Math.ceil((max-min) / h);
      }
docs: Returns the number of bins for a data based on a suggested bin width h.
  @param x the data set.
  @param h the bin width.
  @return the number of bins k = ceil((max - min) / h)