Java BigInteger Calculate product(final BigInteger min, final BigInteger max)

Here you can find the source of product(final BigInteger min, final BigInteger max)

Description

Compute the product of all integers in the range [min,max].

License

Open Source License

Parameter

Parameter Description
min First number to include in product
max Last number to include in product

Return

Product of all integers in range.

Declaration

public static BigInteger product(final BigInteger min, final BigInteger max) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigInteger;

public class Main {
    /**/* w  w w .j  a  va  2s .c  o  m*/
     * Compute the product of all integers in the range [min,max].
     * @param min First number to include in product
     * @param max Last number to include in product
     * @return Product of all integers in range.
     */
    public static BigInteger product(final BigInteger min, final BigInteger max) {
        BigInteger ret = BigInteger.ONE;
        for (BigInteger i = min; i.compareTo(max) <= 0; i = i.add(BigInteger.ONE)) {
            ret = ret.multiply(i);
        }
        return ret;
    }

    /**
     * Compute the product of all integers in the range [min,max].
     * @param min First number to include in product
     * @param max Last number to include in product
     * @return Product of all integers in range.
     */
    public static long product(final long min, final long max) {
        long ret = 1;
        for (long i = min; i <= max; ++i) {
            ret *= i;
        }
        return ret;
    }
}

Related

  1. numberToShortString(BigInteger number)
  2. order(BigInteger a, BigInteger p, BigInteger f[], BigInteger e[])
  3. parseBigInteger(String s, BigInteger defaultValue)
  4. parseBinaryBigInteger(final byte[] buffer, final int offset, final int length, final boolean negative)
  5. parseScaledNonNegativeBigInteger(String str)
  6. randomFromZn(BigInteger n, Random rand)
  7. removeDuplicates(final BigInteger... values)
  8. renderBigInteger(final BigInteger bint)
  9. retrieveBigInteger(final byte[] buf, final int offset)