當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Java.lang.StrictMath.max()用法及代碼示例


描述

這個java.lang.StrictMath.max(double a, double b) 方法返回兩個雙精度值中較大的一個。

如果參數具有相同的值,則結果是相同的值。如果任一值為 NaN,則結果為 NaN。

該方法認為負零嚴格小於正零。如果一個參數為正零,另一個為負零,則結果為正零。

聲明

以下是聲明java.lang.StrictMath.max()方法

public static double max(double a, double b)

參數

  • a- 這是雙值。

  • b- 這是另一個雙重值。

返回值

此方法返回 a 和 b 中較大的一個。

異常

NA

示例

下麵的例子展示了 java.lang.StrictMath.max() 方法的用法。

package com.tutorialspoint;

import java.lang.*;

public class StrictMathDemo {

   public static void main(String[] args) {

      double d1 = 85 , d2 = 20, d3 = -10;

      // both positive values
      double maxValue = StrictMath.max(d1, d2); 
      System.out.println("StrictMath.max(85, 20):" + maxValue);
 
      // one positive and one negative value
      maxValue = StrictMath.max(d1, d3); 
      System.out.println("StrictMath.max(85, -10):" + maxValue);    
   }
}

讓我們編譯並運行上麵的程序,這將產生以下結果 -

StrictMath.max(85, 20):85.0
StrictMath.max(85, -10):85.0

相關用法


注:本文由純淨天空篩選整理自 Java.lang.StrictMath.max() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。