java.lang.StrictMath Class

The StrictMath class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.

In this tutorial you can learn how to use StrictMath class. You need not to create instance for StrictMath class. Because all the methods in StrictMath class are static methods. All the static methods are called with the class name.

java.lang.StrictMath Class Example
/* Save with file name StrictMathExample.java */

public class StrictMathExample
{
	public static void main(String args[])
	{
		//IF THE VALUE IS NEGITIVE IT RETURNS POSITIVE VALUE
		System.out.println("Absolute : " + StrictMath.abs(-100.50));

		//IT INCREASE THE VALUE TO NEAREST INTEGER
		System.out.println("ceil : " + StrictMath.ceil(100.55));

		//IT DECREASE THE VALUE TO NEAREST INTEGER
		System.out.println("floor : " + StrictMath.floor(100.55));

		//IT RETURNS MAX NUMBER WITH IN THE GIVEN NUMBERS
		System.out.println("max : " + StrictMath.max(100,200));

		//IT RETURNS MIN NUMBER WITH IN THE GIVEN NUMBERS
		System.out.println("min : " + StrictMath.min(100,200));

		//IT RETURNS RANDOM NUMBER
		System.out.println("random : " + StrictMath.random());

		//IT RETURNS WITHOUT FLOATING POINT
		System.out.println("round : " + StrictMath.round(100.75));

		//IT RETURNS SQUARE ROOT
		System.out.println("sqrt : " + StrictMath.sqrt(2));

		//IT RETURNS PI VALUE (22/7)
		System.out.println("PI : " + StrictMath.PI);

		//RETURNS NATURAL LOGARITHM
		System.out.println("log : " + StrictMath.log(10.55));

		//RETURNS BASE 10 LOGARITHM
		System.out.println("log10 : " + StrictMath.log10(10.55));

		//RETURNS NATURAL LOGARITHM OF SUM OF THE ARGUMENT AND 1
		System.out.println("log1p : " + StrictMath.log1p(10.55));
	}
}
                        

In the following example you can learn how to use trigonometric functions in java.

java.lang.StrictMath Class Example 2
/* Save with file name StrictMathExample2.java */

public class StrictMathExample2
{
	public static void main(String args[])
	{
		//RETURNS ARC COSINE
		System.out.println("acos : " + StrictMath.acos(0.4));

		//RETURNS ARC SINE
		System.out.println("asin : " + StrictMath.asin(0.4));

		//RETURNS ARC TANGENT VALUE
		System.out.println("atan : " + StrictMath.atan(45));

		//RETURNS COSINE OF AN ANGLE
		System.out.println("cos : " + StrictMath.cos(45));

		//RETURNS HYPERBOLIC COSINE
		System.out.println("cosh : " + StrictMath.cosh(45));

		//RETURNS SINE OF AN ANGLE
		System.out.println("sin : " + StrictMath.sin(45));

		//RETURNS HYPERBOLIC SINE
		System.out.println("sinh : " + StrictMath.sinh(45));

		//RETURNS TANGENT OF AN ANGLE
		System.out.println("tan : " + StrictMath.tan(45));

		//RETURNS HYPERBOLIC TANGENT
		System.out.println("tanh : " + StrictMath.tanh(45));

		//RETURNS DEGREES
		System.out.println("toDegrees : " + StrictMath.toDegrees(45));

		//RETURNS RADIANS
		System.out.println("toRadians : " + StrictMath.toRadians(45));
	}
}