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


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


描述

這個java.lang.StrictMath.max(int a, int b) 方法返回兩個 int 值中的較大者。也就是說,結果是更接近 Integer.MAX_VALUE 值的參數。如果參數具有相同的值,則結果是相同的值。

聲明

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

public static int max(int a, int b)

參數

  • a- 這是整數值。

  • b- 這是另一個 int 值。

返回值

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

異常

NA

示例

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

package com.tutorialspoint;

import java.lang.*;

public class StrictMathDemo {

   public static void main(String[] args) {

      int i1 = 45 , i2 = 20, i3 = -15;
   
      // both positive values
      double maxValue = StrictMath.max(i1, i2); 
      System.out.println("StrictMath.max(45, 20):" + maxValue);

      // one positive and one negative value
      maxValue = StrictMath.max(i1, i3); 
      System.out.println("StrictMath.max(45, -15):" + maxValue);    
   }
}

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

StrictMath.max(45, 20):45.0
StrictMath.max(45, -15):45.0

相關用法


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