Facebook Page Twitter Page LinkedIn Page
× Java Tutorial Java Advanced Java Resources

The Java Math max() method is used to return 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.


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) 


arg1 Specify value to compare.
arg2 Specify value to compare.

Return Value

Returns the numerically maximum value.




In the below example, 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:


❮ Java Math Methods