Package de.alpharogroup.math
Class MathExtensions
- java.lang.Object
-
- de.alpharogroup.math.MathExtensions
-
public final class MathExtensions extends java.lang.ObjectUtility class for the use numbers.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intgetNumberOfDigits(int number)Gets the number of digits from the givenintnumber.static int[]getPrimeNumbers(int quantity)Gets the prime numbers for the given quantity.static booleanisBetween(double min, double max, double index)Checks the given double index is between the range from min and max.static booleanisBetween(double min, double max, double index, boolean includeMin, boolean includeMax)Checks the given double index is between the range from min and max.static booleanisBetween(float min, float max, float index)Checks the given float index is between the range from min and max.static booleanisBetween(float min, float max, float index, boolean includeMin, boolean includeMax)Checks the given float index is between the range from min and max.static booleanisBetween(int min, int max, int index)Checks the given int index is between the range from min and max.static booleanisBetween(int min, int max, int index, boolean includeMin, boolean includeMax)Checks the given int index is between the range from min and max.static booleanisBetween(long min, long max, long index)Checks the given long index is between the range from min and max.static booleanisBetween(long min, long max, long index, boolean includeMin, boolean includeMax)Checks the given long index is between the range from min and max.static booleanisInRange(int min, int max, int number)Checks the given number is in range from min and max.static booleanisNegative(double number)Checks if the number is negative.static booleanisNegative(float number)Checks if the number is negative.static booleanisNegative(int number)Checks if the number is negative.static booleanisNegative(long number)Checks if the number is negative.static booleanisNext(java.lang.Integer number, java.lang.Integer nextNumber)Checks if the givenIntegernextNumber is next to the givenIntegernumber.static booleanisPositive(double number)Checks if the number is positive.static booleanisPositive(float number)Checks if the number is positive.static booleanisPositive(int number)Checks if the number is positive.static booleanisPositive(long number)Checks if the number is positive.static booleanisPrevious(java.lang.Integer number, java.lang.Integer previousNumber)Checks if the givenIntegerpreviousNumber is previous to the givenIntegernumber.static booleanisPrime(double n)Checks if the given float is a prime number.static booleanisPrime(float n)Checks if the given float is a prime number.static booleanisPrime(int n)Checks if the given int is a prime number.static booleanisPrime(long n)Checks if the given long is a prime number.static booleanisPrimeNumber(int number)Checks if the number is a prime number.static doublepercentageOf(double value, double percentage)Calculates the percentage of the given valuestatic int[]printAllPrimeNumbersTill(int noOfPrimes)Prints all prime numbers till the given number.
-
-
-
Method Detail
-
getNumberOfDigits
public static int getNumberOfDigits(int number)
Gets the number of digits from the givenintnumber.- Parameters:
number- the number- Returns:
- the number of digits
-
getPrimeNumbers
public static int[] getPrimeNumbers(int quantity)
Gets the prime numbers for the given quantity.- Parameters:
quantity- The quantity.- Returns:
- An array from prime numbers.
-
isBetween
public static boolean isBetween(double min, double max, double index)Checks the given double index is between the range from min and max.- Parameters:
min- The minimum.max- The maximum.index- The index.- Returns:
- Returns true if the index is betwenn the range from min and max otherwise false.
-
isBetween
public static boolean isBetween(double min, double max, double index, boolean includeMin, boolean includeMax)Checks the given double index is between the range from min and max.- Parameters:
min- The minimum.max- The maximum.index- The index.includeMin- if true than min value is includedincludeMax- if true than max value is included- Returns:
- Returns true if the index is between the range from min and max considered the given flags otherwise false.
-
isBetween
public static boolean isBetween(float min, float max, float index)Checks the given float index is between the range from min and max.- Parameters:
min- The minimum.max- The maximum.index- The index.- Returns:
- Returns true if the index is betwenn the range from min and max otherwise false.
-
isBetween
public static boolean isBetween(float min, float max, float index, boolean includeMin, boolean includeMax)Checks the given float index is between the range from min and max.- Parameters:
min- The minimum.max- The maximum.index- The index.includeMin- if true than min value is includedincludeMax- if true than max value is included- Returns:
- Returns true if the index is between the range from min and max considered the given flags otherwise false.
-
isBetween
public static boolean isBetween(int min, int max, int index)Checks the given int index is between the range from min and max.- Parameters:
min- The minimum.max- The maximum.index- The index.- Returns:
- Returns true if the index is betwenn the range from min and max otherwise false.
-
isBetween
public static boolean isBetween(int min, int max, int index, boolean includeMin, boolean includeMax)Checks the given int index is between the range from min and max.- Parameters:
min- The minimum.max- The maximum.index- The index.includeMin- if true than min value is includedincludeMax- if true than max value is included- Returns:
- Returns true if the index is between the range from min and max considered the given flags otherwise false.
-
isBetween
public static boolean isBetween(long min, long max, long index)Checks the given long index is between the range from min and max.- Parameters:
min- The minimum.max- The maximum.index- The index.- Returns:
- Returns true if the index is betwenn the range from min and max otherwise false.
-
isBetween
public static boolean isBetween(long min, long max, long index, boolean includeMin, boolean includeMax)Checks the given long index is between the range from min and max.- Parameters:
min- The minimum.max- The maximum.index- The index.includeMin- if true than min value is includedincludeMax- if true than max value is included- Returns:
- Returns true if the index is between the range from min and max considered the given flags otherwise false.
-
isInRange
public static boolean isInRange(int min, int max, int number)Checks the given number is in range from min and max.- Parameters:
min- The minimum.max- The maximum.number- The index.- Returns:
- Returns true if the number is in range from min and max otherwise false.
-
isNegative
public static boolean isNegative(double number)
Checks if the number is negative.- Parameters:
number- The number.- Returns:
- Returns true if the number is negative otherwise false.
-
isNegative
public static boolean isNegative(float number)
Checks if the number is negative.- Parameters:
number- The number.- Returns:
- Returns true if the number is negative otherwise false.
-
isNegative
public static boolean isNegative(int number)
Checks if the number is negative.- Parameters:
number- The number.- Returns:
- Returns true if the number is negative otherwise false.
-
isNegative
public static boolean isNegative(long number)
Checks if the number is negative.- Parameters:
number- The number.- Returns:
- Returns true if the number is negative otherwise false.
-
isNext
public static boolean isNext(java.lang.Integer number, java.lang.Integer nextNumber)Checks if the givenIntegernextNumber is next to the givenIntegernumber.
Example:
isNext(1, 2); => true;
isNext(1, 3); => false;
isNext(4, 3); => false;- Parameters:
number- the numbernextNumber- the next number- Returns:
- true, if the given
IntegernextNumber is next to the givenIntegernumber otherwise false.
-
isPositive
public static boolean isPositive(double number)
Checks if the number is positive.- Parameters:
number- The number.- Returns:
- Returns true if the number is positive otherwise false.
-
isPositive
public static boolean isPositive(float number)
Checks if the number is positive.- Parameters:
number- The number.- Returns:
- Returns true if the number is positive otherwise false.
-
isPositive
public static boolean isPositive(int number)
Checks if the number is positive.- Parameters:
number- The number.- Returns:
- Returns true if the number is positive otherwise false.
-
isPositive
public static boolean isPositive(long number)
Checks if the number is positive.- Parameters:
number- The number.- Returns:
- Returns true if the number is positive otherwise false.
-
isPrevious
public static boolean isPrevious(java.lang.Integer number, java.lang.Integer previousNumber)Checks if the givenIntegerpreviousNumber is previous to the givenIntegernumber.
Example:
isPrevious(1, 2); => false;
isPrevious(1, 3); => false;
isPrevious(4, 3); => true;- Parameters:
number- the numberpreviousNumber- the previous number- Returns:
- true, if the given
IntegerpreviousNumber is previous to the givenIntegernumber otherwise false.
-
isPrime
public static boolean isPrime(double n)
Checks if the given float is a prime number.- Parameters:
n- The int to check.- Returns:
- Returns true if the float is a prime number otherwise false.
-
isPrime
public static boolean isPrime(float n)
Checks if the given float is a prime number.- Parameters:
n- The int to check.- Returns:
- Returns true if the float is a prime number otherwise false.
-
isPrime
public static boolean isPrime(int n)
Checks if the given int is a prime number.- Parameters:
n- The int to check.- Returns:
- Returns true if the int is a prime number otherwise false.
-
isPrime
public static boolean isPrime(long n)
Checks if the given long is a prime number.- Parameters:
n- The int to check.- Returns:
- Returns true if the long is a prime number otherwise false.
-
isPrimeNumber
public static boolean isPrimeNumber(int number)
Checks if the number is a prime number.- Parameters:
number- The number.- Returns:
- Returns true if the number is a prime number otherwise false.
-
printAllPrimeNumbersTill
public static int[] printAllPrimeNumbersTill(int noOfPrimes)
Prints all prime numbers till the given number.- Parameters:
noOfPrimes- The limit.- Returns:
- an array of all prime numbers till the given number.
-
percentageOf
public static double percentageOf(double value, double percentage)Calculates the percentage of the given value- Parameters:
value- The valuepercentage- The percentage- Returns:
- the result of the percentage of the given value
-
-