Java.lang.StrictMath.max() Method



Description

The java.lang.StrictMath.max(float a, float b) method returns the greater of two float values.

If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN.

This method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other negative zero, the result is positive zero.

Declaration

Following is the declaration for java.lang.StrictMath.max() method

public static float max(float a, float b)

Parameters

  • a − This is the float value.

  • b − This is another float value.

Return Value

This method returns the larger of a and b.

Exception

NA

Example

The following example shows the usage of java.lang.StrictMath.max() method.

package com.tutorialspoint;

import java.lang.*;

public class StrictMathDemo {

   public static void main(String[] args) {

      float f1 = 60 , f2 = 40, f3 = -5;
   
      // both positive values
      double maxValue = StrictMath.max(f1, f2); 
      System.out.println("StrictMath.max(60, 40) : " + maxValue);

      // one positive and one negative value
      maxValue = StrictMath.max(f1, f3); 
      System.out.println("StrictMath.max(60, -5) : " + maxValue);    
   }
}

Let us compile and run the above program, this will produce the following result −

StrictMath.max(60, 40) : 60.0
StrictMath.max(60, -5) : 60.0
java_lang_strictmath.htm
Advertisements