Java.lang Package Classes

Java StrictMath - max() Method



The java.lang.StrictMath.max() method returns maximum number between the two arguments. If either of the arguments is NaN, then the result is NaN.

Syntax

public static int max(int a, int b) 

Parameters

a Specify value to compare.
b 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.

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  int x1 = 50;
  int y1 = 100;
  int x2 = -5;
  int y2 = -10;

  System.out.println(StrictMath.max(x1, y1)); 
  System.out.println(StrictMath.max(x2, y2));   
 }
}

The output of the above code will be:

100
-5

❮ Java.lang - StrictMath