StrictMath min() Method in Java with Examples

The java.lang.StrictMath.min() method returns the smaller of two values. There are four variations of this method with different types of parameters passed.
All of them are discussed below :

1. min(double num1, double num2) is the inbuilt method of StrictMath class which is used to get the least of given two double values arguments. It returns NaN when any of the arguments is NaN. It returns the same value when num1 and num2 have the same value. min() method assumes negative zero to be strictly smaller than positive zero.It returns negative zero when one argument is positive zero and the other is negative zero.
Syntax :

`public static double min(double num1, double num2)`

Parameters : The method accepts a two parameter :

• num1 of double type representing one parameter
• num2 of double type representing another parameter

Return Value : The method returns the least of num1 and num2.

Examples :

```Input:
num1 = 9
nm2 = 99
Output: 9.0
```

Below programs illustrate the Java.lang.StrictMath.min() Method.
Program 1:

 `// Java praogram to illustrate the ` `// Java.lang.StrictMath.min() Method ` `// with double values passed ` `// as parameters ` `import` `java.lang.*; ` ` `  `public` `class` `Geeks { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``double` `num1 = ``10``, num2 = ``40``, num3 = -``25``, num4 = -``25``, ` `               ``num5 = -``17``; ` ` `  `        ``double` `min_Value = StrictMath.min(num1, num2); ` `        ``System.out.println(``"min of the two num is "` `+ min_Value); ` ` `  `        ``min_Value = StrictMath.min(num3, num4); ` `        ``System.out.println(``"min of the two num is "` `+ min_Value); ` ` `  `        ``min_Value = StrictMath.min(num4, num5); ` `        ``System.out.println(``"min of the two num is "` `+ min_Value); ` `    ``} ` `} `

Output:

```min of the two num is 10.0
min of the two num is -25.0
min of the two num is -25.0
```

Example of Error Condition :

 `// Java praogram to illustrate the ` `// error condition in ` `// Java.lang.StrictMath.min() Method ` `import` `java.lang.*; ` ` `  `public` `class` `Geeks { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``double` `num1 = ``51``, num2 = ``71``, num3 = ``3``, num4 = -``93``, ` `               ``num5 = -``93``; ` `        ``double` `a = ``0.0``; ` ` `  `        ``num1 = a / ``0.0``; ` `        ``double` `min_Value = StrictMath.min(num1, a); ` `        ``System.out.println(``"min of the two num is "` `+ min_Value); ` `    ``} ` `} `

Output:

```min of the two num is NaN
```
2. The min(float num1, float num2) is the inbuilt method of StrictMath class which is used to get the least of given two float values arguments.It returns NaN when any of the arguments is NaN.It returns the same value when num1 and num2 have the same value. min() method assumes negative zero to be strictly smaller than positive zero.It returns negative zero when one argument is positive zero and the other is negative zero.
Syntax :

`public static float min(float num1, float num2)`

Parameters : The method accepts a two parameter :

• num1 of float type representing one parameter
• num2 of float type representing another parameter

Return Value : The method returns the least of num1 and num2.

Examples :

```Input:
num1 = 9
nm2 = 5
Output: 5.0
```

Below programs illustrate the Java.lang.StrictMath.min() Method.
Program 1:

 `// Java praogram to illustrate the ` `// Java.lang.StrictMath.min() Method ` `// with float values passed ` `// as parameters ` `import` `java.lang.*; ` ` `  `public` `class` `Geeks { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``float` `num1 = ``28``, num2 = ``82``, num3 = -``23``, num4 = -``23``, ` `              ``num5 = -``11``; ` ` `  `        ``float` `min_Value = StrictMath.min(num1, num2); ` `        ``System.out.println(``"min of the two num is "` `+ min_Value); ` ` `  `        ``min_Value = StrictMath.min(num3, num4); ` `        ``System.out.println(``"min of the two num is "` `+ min_Value); ` ` `  `        ``min_Value = StrictMath.min(num4, num5); ` `        ``System.out.println(``"min of the two num is "` `+ min_Value); ` `    ``} ` `} `

Output:

```min of the two num is 28.0
min of the two num is -23.0
min of the two num is -23.0
```
3. The min(int num1, int num2) is the inbuilt method of StrictMath class which is used to get the least of given two int values arguments.It returns NaN when any of the arguments is NaN.It returns the same value when num1 and num2 have the same value. min() method assumes negative zero to be strictly smaller than positive zero.Simply the argument closer to the value of Integer.MIN_VALUE is the result.
Syntax :

`public static int min(int num1, int num2)`

Parameters : The method accepts a two parameter :

• num1 of int type representing one parameter
• num2 of int type representing another parameter

Return Value : The method returns the least of num1 and num2.

Examples :

```Input:
num1 = 61
nm2 = 18
Output: 5.0
```

Below programs illustrate the Java.lang.StrictMath.min() Method.
Program 1:

 `// Java praogram to illustrate the ` `// Java.lang.StrictMath.min() Method ` `// with int values passed ` `// as parameters ` `import` `java.lang.*; ` ` `  `public` `class` `Geeks { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``int` `num1 = ``51``, num2 = ``71``, num3 = -``74``, num4 = -``93``, ` `            ``num5 = -``93``; ` ` `  `        ``double` `min_Value = StrictMath.min(num1, num2); ` `        ``System.out.println(``"min of the two num is "` `+ min_Value); ` ` `  `        ``min_Value = StrictMath.min(num3, num4); ` `        ``System.out.println(``"min of the two num is "` `+ min_Value); ` ` `  `        ``min_Value = StrictMath.min(num4, num5); ` `        ``System.out.println(``"min of the two num is "` `+ min_Value); ` `    ``} ` `} `

Output:

```min of the two num is 51.0
min of the two num is -93.0
min of the two num is -93.0
```
4. The min(long num1, long num2) is the inbuilt method of StrictMath class which is used to get the least of given two long values arguments.It returns NaN when any of the arguments is NaN.It returns the same value when num1 and num2 have the same value. min() method assumes negative zero to be strictly smaller than positive zero.Simply the argument closer to the value of Long.MIN_VALUE is the result.
Syntax :

`public static long min(long num1, long num2)`

Parameters : The method accepts a two parameter :

• num1 of long type representing one parameter
• num2 of long type representing another parameter

Return Value : The method returns the least of num1 and num2.

Examples :

```Input:
num1 = 51617
nm2 = 1345
Output: 1345.0
```

Below programs illustrate the Java.lang.StrictMath.min() Method.
Program 1:

 `// Java praogram to illustrate the ` `// Java.lang.StrictMath.min() Method ` `// with long values passed ` `// as parameters ` `import` `java.lang.*; ` ` `  `public` `class` `Geeks { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``long` `num1 = ``265626``, num2 = ``66671``, num3 = -``776264``, num4 = -``9263``, ` `             ``num5 = -``97623``; ` ` `  `        ``double` `min_Value = StrictMath.min(num1, num2); ` `        ``System.out.println(``"min of the two num is "` `+ min_Value); ` ` `  `        ``min_Value = StrictMath.min(num3, num4); ` `        ``System.out.println(``"min of the two num is "` `+ min_Value); ` ` `  `        ``min_Value = StrictMath.min(num4, num5); ` `        ``System.out.println(``"min of the two num is "` `+ min_Value); ` `    ``} ` `} `

Output:

```min of the two num is 66671.0
min of the two num is -776264.0
min of the two num is -97623.0
```

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.