Java Math - max() Method
The Java max() method returns maximum number between the two arguments. The method can be overloaded and it can take int, double, float and long arguments. If either of the arguments is NaN, then the result is NaN.
Syntax
public static int max(int arg1, int arg2) public static long max(long arg1, long arg2) public static float max(float arg1, float arg2) public static double max(double arg1, double arg2)
Parameters
arg1 |
Specify value to compare. |
arg2 |
Specify value to compare. |
Return Value
Returns the numerically maximum value.
Exception
NA.
Example:
In the example below, max() method is used to find out the maximum value between the two arguments.
public class MyClass { public static void main(String[] args) { System.out.println(Math.max(50, 100)); System.out.println(Math.max(5.5, 10.5)); } }
The output of the above code will be:
100 10.5
❮ Java Math Methods