juggernaut.mef

Class Numbers

public class Numbers extends Object

Field Summary
static doublePHI
Method Summary
static StringconvBase(String n, int base1, int base2)
static intfactorial(int n)
Returns the factorial of x which is the product of the integers from 1 to x.
static doublefPart(double n)
Returns the fraction or decimal component of a {@code double}.
static floatfPart(float n)
Returns the fraction or decimal component of a {@code float}.
static intnCr(int n, int r)
Returns the number of ways to choose r objects among n choices without respect to order.
static intnDigits(int n)
Returns the number of digits in a given {@code int}.
static intnDigits(int n, int base)
Returns the number of digits in a specified base of a base 10 number.
static intnPr(int n, int r)
Returns the number of ways to choose r objects among n choices with respect to order.
static long[]pascal(int r)
Returns the specified row of Pascal's triangle.
{@code pascal(0)} = [1],
{@code pascal(1)} = [1 1],
{@code pascal(2)} = [1 2 1],
{@code pascal(3)} = [1 3 3 1], etc.
static StringtoBase(int n, int base)
static inttoBase10(String n, int base)
static int[]toDigits(int n)

Field Detail

PHI

public static final double PHI

Method Detail

convBase

public static String convBase(String n, int base1, int base2)

factorial

public static int factorial(int n)
Returns the factorial of x which is the product of the integers from 1 to x. For instance 4 factorial = 4! = 4 * 3 * 2 * 1 = 24.

Returns: x! (x factorial)

fPart

public static double fPart(double n)
Returns the fraction or decimal component of a {@code double}.

Parameters: n the number

Returns: The decimal part of the number.

fPart

public static float fPart(float n)
Returns the fraction or decimal component of a {@code float}.

Parameters: n the number

Returns: The decimal part of the number.

nCr

public static int nCr(int n, int r)
Returns the number of ways to choose r objects among n choices without respect to order. Both n and r must be nonnegative.

Parameters: n the total number of objects r the amount to choose

Returns: The number of of ways to choose r objects among n choices.

nDigits

public static int nDigits(int n)
Returns the number of digits in a given {@code int}.

Parameters: n a double

Returns: The number of digits in the integer.

nDigits

public static int nDigits(int n, int base)
Returns the number of digits in a specified base of a base 10 number.

Parameters: n the number base the base

Returns: The number of digits of the number in that base.

nPr

public static int nPr(int n, int r)
Returns the number of ways to choose r objects among n choices with respect to order. Both n and r must be nonnegative.

Parameters: n the total number of objects r the amount to choose

Returns: The number of of ways to choose r objects among n choices.

pascal

public static long[] pascal(int r)
Returns the specified row of Pascal's triangle.
{@code pascal(0)} = [1],
{@code pascal(1)} = [1 1],
{@code pascal(2)} = [1 2 1],
{@code pascal(3)} = [1 3 3 1], etc.

Parameters: r the number row of Pascal's triangle

Returns: The row of Pascal's triangle.

toBase

public static String toBase(int n, int base)

toBase10

public static int toBase10(String n, int base)

toDigits

public static int[] toDigits(int n)