General Java

Java Math Class Methods With Examples3 min read

Java Math max() method with Examples

The Java.lang.math.max() function is an inbuilt function in Java which returns maximum of two numbers. The arguments are taken in int, double, float and long.If a negative and a positive number is passed as argument then the positive result is generated. And if both parameters passed are negative then the number with the lower magnitude is generated as result.

Given below are the examples of the function max()

Output:

Output:




Output:

 

Java Math min() method with Examples

The Math.min(x,y) method can be used to find the lowest value of of x and y:

 

Java Math sqrt() method with Examples

The Math.sqrt(x) method returns the square root of x:

 

Java Math abs() method with Examples

The Math.abs(x) method returns the absolute (positive) value of x:

 

Java Math random() method with Examples

Math.random() returns a random number between 0 (inclusive), and 1 (exclusive):

 

Java Math multiplyFull() method with Examples

The multiplyFull(int x, int y) method of Math class is used to return the exact mathematical product of the two arguments. In the parameters, two integer values are provided and the product of both numbers expressed in long type returned by this method.

 

Java Math copySign() method with Examples

The java.lang.Math.copySign() method returns the first argument with the sign of the second argument.

Note:
Arguments can be of two types:

  • double type : copySign(double magt, double sign)
  • float type : copySign(float magt, float sign)
 

 

Leave a Comment