Java.lang.StrictMath.min() Method

Advertisements


Description

The java.lang.StrictMath.min(float a, float b) method returns the smaller 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 is negative zero, the result is negative zero.

Declaration

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

public static float min(float a, float b)

Parameters

  • a -- This is the float value.

  • b -- This is another float value.

Return Value

This method returns the smaller of a and b.

Exception

  • NA

Example

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

package com.tutorialspoint;

import java.lang.*;

public class StrictMathDemo {

  public static void main(String[] args) {
  
    float f1 = 50 , f2 = 100, f3 = -25;

    // both positive values
    double minValue = StrictMath.min(f1, f2); 
    System.out.println("StrictMath.min(50, 100) : " + minValue);
        
    // one positive and one negative value
    minValue = StrictMath.min(f1, f3); 
    System.out.println("StrictMath.min(50, -25) : " + minValue);    
  }
}

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

StrictMath.min(50, 100) : 50.0
StrictMath.min(50, -25) : -25.0



Advertisements
Advertisements