Class MathExtensions


  • public final class MathExtensions
    extends java.lang.Object
    Utility class for the use numbers.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int getNumberOfDigits​(int number)
      Gets the number of digits from the given int number.
      static int[] getPrimeNumbers​(int quantity)
      Gets the prime numbers for the given quantity.
      static boolean isBetween​(double min, double max, double index)
      Checks the given double index is between the range from min and max.
      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.
      static boolean isBetween​(float min, float max, float index)
      Checks the given float index is between the range from min and max.
      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.
      static boolean isBetween​(int min, int max, int index)
      Checks the given int index is between the range from min and max.
      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.
      static boolean isBetween​(long min, long max, long index)
      Checks the given long index is between the range from min and max.
      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.
      static boolean isInRange​(int min, int max, int number)
      Checks the given number is in range from min and max.
      static boolean isNegative​(double number)
      Checks if the number is negative.
      static boolean isNegative​(float number)
      Checks if the number is negative.
      static boolean isNegative​(int number)
      Checks if the number is negative.
      static boolean isNegative​(long number)
      Checks if the number is negative.
      static boolean isNext​(java.lang.Integer number, java.lang.Integer nextNumber)
      Checks if the given Integer nextNumber is next to the given Integer number.
      static boolean isPositive​(double number)
      Checks if the number is positive.
      static boolean isPositive​(float number)
      Checks if the number is positive.
      static boolean isPositive​(int number)
      Checks if the number is positive.
      static boolean isPositive​(long number)
      Checks if the number is positive.
      static boolean isPrevious​(java.lang.Integer number, java.lang.Integer previousNumber)
      Checks if the given Integer previousNumber is previous to the given Integer number.
      static boolean isPrime​(double n)
      Checks if the given float is a prime number.
      static boolean isPrime​(float n)
      Checks if the given float is a prime number.
      static boolean isPrime​(int n)
      Checks if the given int is a prime number.
      static boolean isPrime​(long n)
      Checks if the given long is a prime number.
      static boolean isPrimeNumber​(int number)
      Checks if the number is a prime number.
      static double percentageOf​(double value, double percentage)
      Calculates the percentage of the given value
      static int[] printAllPrimeNumbersTill​(int noOfPrimes)
      Prints all prime numbers till the given number.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getNumberOfDigits

        public static int getNumberOfDigits​(int number)
        Gets the number of digits from the given int number.
        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 included
        includeMax - 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 included
        includeMax - 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 included
        includeMax - 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 included
        includeMax - 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 given Integer nextNumber is next to the given Integer number.
        Example:
        isNext(1, 2); => true;
        isNext(1, 3); => false;
        isNext(4, 3); => false;
        Parameters:
        number - the number
        nextNumber - the next number
        Returns:
        true, if the given Integer nextNumber is next to the given Integer number 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 given Integer previousNumber is previous to the given Integer number.
        Example:
        isPrevious(1, 2); => false;
        isPrevious(1, 3); => false;
        isPrevious(4, 3); => true;
        Parameters:
        number - the number
        previousNumber - the previous number
        Returns:
        true, if the given Integer previousNumber is previous to the given Integer number 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 value
        percentage - The percentage
        Returns:
        the result of the percentage of the given value