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


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


描述

這個java.lang.Math.max(double a, double b)返回兩個雙精度值中的較大者。也就是說,結果是更接近正無窮大的論證。如果參數具有相同的值,則結果是相同的值。如果任一值為 NaN,則結果為 NaN。與數值比較運算符不同,此方法認為負零嚴格小於正零。如果一個參數為正零,另一個為負零,則結果為正零。

聲明

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

public static double max(double a, double b)

參數

  • a─ 一個論點

  • b─ 另一個論點

返回值

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

異常

NA

示例

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

package com.tutorialspoint;

import java.lang.*;

public class MathDemo {

   public static void main(String[] args) {

      // get two double numbers
      double x = 60984.1;
      double y = 1000;
   
      // print the larger number between x and y
      System.out.println("Math.max(" + x + "," + y + ")=" + Math.max(x, y));
   }
}

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

Math.max(60984.1, 1000)=60984.1

相關用法


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