Java Math max() Method

Facebooktwitterredditpinterestlinkedinmailby feather

The max() method of Math class returns the greater of two arguments. The arguments can be of double, float, int or long data type.

Syntax:

  1. public static double max(double a, double b)
  2. public static float max(float a, float b)
  3. public static int max(int a, int b)
  4. public static long max(long a, long b)

Parameters:

The parameters ‘a’ and ‘b’ represent the two values.

Return Value:

The max() method returns the larger of a and b.

  • It returns the result of same value, is the arguments have same value
  • It returns NaN, if either value is NaN.
  • It returns positive zero, if one argument is positive zero and the other is negative zero.

Example 1:

Output:

Example 2:

Output:

Example 3:

Output:

Example 4:

Output:

Example 5:

Output:

Facebooktwitterredditpinterestlinkedinmailby feather