.min()
MinalGhate2 total contributions
Published Oct 22, 2022
Contribute to Docs
The Math.min()
method returns the minimum value from the given two arguments.
Syntax
Math.min(num1, num2)
- The
.min()
method takes two parametersnum1
andnum2
. - The
num1
andnum2
arguments can be of type int, float, double or long.
Example 1
The following example uses the .min()
method to print the minimum of two numbers:
public class Main {public static void main(String[] args){int num1 = 50;int num2 = 10;System.out.println(Math.min(num1, num2));}}
This results in the following output:
10
Example 2
The following example uses the .min()
method to print the minimum of three numbers:
public class Main {public static void main(String[] args){int num1 = 4;int num2 = 10;int num3 = 1;System.out.println(Math.min(Math.min(num1, num2),num3));}}
This results in the following output:
1
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.