Home » Core Java » math

# math

## Java math.random Example

Java provides us Math class, which includes methods with basic numeric operations such as logarithm, square root etc. One of these methods is random(), which give us a pseudorandom positive double number greater than or equal to 0.0 and less than 1.0 – [0.0, 1.0). In this example we are going to show how to produce integer and double random ...

## Generate random Integer within given range

In this example we shall show you how to generate a random Integer within a given range, using random() method of Math. The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. To generate a random Integer within a given range one should perform the following steps: Use random() method of ...

## Find floor value of a number

With this example we are going to demonstrate how to find the floor value of a number, using the floor(double a) API method of Math. Math API provides methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. In short, to find the floor value of a number you should: Use floor(double a) method ...

## Find natural logarithm value of a number

This is an example of how to find the natural logarithm value of a number, using the log(double a) method of Math. The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. Finding the natural logarithm value of a number implies that you should: Use log(double a) API method ...

## Find ceiling value of a number

In this example we shall show you how to find the ceiling value of a number, using the Math Class. The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. To find the ceiling value of a number one should perform the following steps: Use ceil(double a) method of ...

## Round float and double numbers

With this example we are going to demonstrate how to round float and double numbers using round() method of Math. The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. In short, to round float and double numbers you should: Use round(float a) method to get the closest int to ...

## Java BigDecimal Example

This is an example of how to use a BigDecimal in Java. A BigDecimal consists of an arbitrary precision integer unscaled value and a 32-bit integer scale. If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power ...

## Using Math Constants

In this example we shall show you how to get constant numbers using the Math Class. Apart from the methods for performing basic numeric operations such as square root, and trigonometric functions, the Math Class also has methods for getting the e, that is the base of the natural logarithms and the PI, that is the ratio of the circumference of ...