In this Java tutorial, you will learn:

Math.abs in Java Math.round in Java Math.ceil and Math.floor in Java Math.min in Java

All such applications require using complex calculations/equations that are tedious to perform manually. Programmatically, such calculations would involve usage of logarithms, trigonometry, exponential equations, etc.

Now, you cannot have all the log or trigonometry tables hard-coded somewhere in your application or data. The data would be enormous and complex to maintain. Java provides a very useful class for this purpose. It is the Math java class (java.lang.Math). This class provides methods for performing the operations like exponential, logarithm, roots and trigonometric equations too. Let us have a look at the methods provided by the Java Math class. The two most fundamental elements in Math are the ‘e’ (base of the natural logarithm) and ‘pi’ (ratio of the circumference of a circle to its diameter). These two constants are often required in the above calculations/operations. Hence the Math class java provides these two constants as double fields. Math.E – having a value as 2.718281828459045 Math.PI – having a value as 3.141592653589793 A) Let us have a look at the table below that shows us the Basic methods and its description Below is the code implementation of the above methods: Note: There is no need to explicitly import java.lang.Math as its imported implicitly. All its methods are static. Integer Variable Double(decimal) variables

Java Math abs() method with Example

Java Math abs() method returns the absolute value of the argument. Output:

Java Math.round() method with Example

Math.round() method in Java returns the closed int or long as per the argument. Below is the example of math.round Java method. Output:

Java Math.ceil and Math.floor method with Example

The Math.ceil and Math.floor in Java methods are used to return the smallest and largest integer that are greater than or equal to the argument. Below is the Math floor and ceiling Java example. We will get the below output of the math.ceil in Java example. Output:

Java Math.min() method with Example

The Java Math.min() method returns the smallest of the two arguments. Output: B) Let us have a look at the table below that shows us the Exponential and Logarithmic methods and its description- Below is the code implementation of the above methods: (The same variables are used as above) Output: C) Let us have a look at the table below that shows us the Trigonometric methods and its description- Default Arguments are in Radians Below is the code implementation: Output: Now, with the above, you can also design your own scientific calculator in java.