Home » math

Tag Archives: math

How to Generate a Random Int in Java

This article shows how to generate a random Int or integer in Java using different approaches. 1. Introduction Java has several ways to generate a random Integer, primitive or wrapped object, on its environment. Here we’ll see some of these methods listed below: Random classMath classThreadLocalRandom class 2. Pre-requisites The minimum Java version for execute this article’s example is JDK ...

Read More »

Math.pow Java Example

In this article, we examine the Math.pow Java method so as to use exponents in java and we provide some examples of its use. 1. Introduction The java.lang package provides classes and interfaces that are central to the Java programming language. The Math class from the java.lang package contains static methods for performing many common math operations. In java, these ...

Read More »

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 ...

Read More »

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 ...

Read More »

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 ...

Read More »

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 ...

Read More »

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 ...

Read More »

Java BigDecimal Example

In this article we will learn about a primitive data type in java the BigDecimal class in java. We will briefly discuss about the various methods available in the BigDecimal class. 1. What is BigDecimal? This primitive data type in java consists of an arbitrary precision integer unscaled value and a 32-bit integer scale. If zero or positive, the scale ...

Read More »

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 ...

Read More »

Java Absolute Value Example

In this post, we feature a comprehensive Java Absolute Value Example. With this example we are going to demonstrate how to calculate the absolute value of a number, using the Math.abs method of Java Math Class. The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, trigonometric functions and most importantly Math.abs ...

Read More »