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