Java Tutorial Java Advanced Java References

Java Math - min() Method



The Java min() method returns minimum number between the two arguments. The method can be overloaded and it can take int, double, float and long arguments. If either of the arguments is NaN, then the result is NaN.

Syntax

public static int min(int arg1, int arg2) 
public static long min(long arg1, long arg2) 
public static float min(float arg1, float arg2) 
public static double min(double arg1, double arg2)  

Parameters

arg1 Specify value to compare.
arg2 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.

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.min(50, 100)); 
  System.out.println(Math.min(5.5, 10.5));   
 }
}

The output of the above code will be:

50
5.5

❮ Java Math Methods