Java Integer min() Method
Example
Get the smaller of two numbers:
public class Main {
public static void main(String[] args) {
System.out.println(Integer.min(5, 10));
System.out.println(Integer.min(-3, -8));
}
}
Definition and Usage
The min() method returns the smaller of two int values.
It gives the same result as Math.min().
Tip: Use the max() method to get the larger of two values.
Syntax
public static int min(int a, int b)
Parameter Values
| Parameter | Description |
|---|---|
| a | Required. The first number. |
| b | Required. The second number. |
Technical Details
| Returns: | The smaller of a and b, as an int. |
|---|
Related Pages
❮ Integer Methods