Java Math min() Method

Facebooktwitterredditpinterestlinkedinmailby feather

The min () method of Math class returns the smaller of two arguments. The arguments can be of double, float, int or long data type.

Syntax:

  1. public static double min (double a, double b)
  2. public static float min (float a, float b)
  3. public static int min (int a, int b)
  4. public static long min (long a, long b)

Parameters:

The parameters ‘a’ and ‘b’ represent the two values.

Return Value:

The min() method returns the smaller of a and b.

  • It returns the result of same value, if the arguments have same value
  • It returns NaN, if either value is NaN.
  • It returns negative zero, if one argument is positive zero and the other is negative zero.

Example 1:

Output:

Example 2:

Output:

Example 3:

Output:

Example 4:

Output:

Facebooktwitterredditpinterestlinkedinmailby feather