Java.lang Package Classes

Java Math - min() Method



The java.lang.Math.min() method returns minimum number between the two arguments. If either of the arguments is NaN, then the result is NaN.

Syntax

public static double min(double a, double b)  

Parameters

a Specify value to compare.
b Specify value to compare.

Return Value

Returns the numerically minimum value.

Exception

NA.

Example:

In the example below, min() method is used to find out the minimum value between the two arguments.

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  double x1 = 50;
  double y1 = 100;
  double x2 = -5.5;
  double y2 = -10.5;

  System.out.println(Math.min(x1, y1)); 
  System.out.println(Math.min(x2, y2));   
 }
}

The output of the above code will be:

50.0
-10.5

❮ Java.lang - Math

5