Java Math.min Method

The purpose of the Java Math.min() method is to find the smallest of the two numbers. This numbers may be positive or negative.

Java Math.min Method

 Java Math.min() method can be used with four data types (int, double, float, long) as input arguments.

java math.min

Example 1: Find the smallest of the two numbers 119.316546 and 119.3165461

double num1 = 119.316546; 
double num2 = 119.3165461; 

double min = Math.min(num1, num2);
System.out.println(min); //119.316546

Example 2: Find the smallest of the two numbers 21 and -21 (one positive and one negative value).

int num1 = 21; 
int num2 = -21; 

int min = Math.min(num1, num2);
System.out.println(min); //-21

Example 3: Find the smallest of the two numbers -60 and -600 (two negative numbers).

int num1 = -60; 
int num2 = -600; 

int min = Math.min(num1, num2);
System.out.println(min); //-600