本文共 1873 字,大约阅读时间需要 6 分钟。
max() method is available in java.math package.
max()方法在java.math包中可用。
max() method is used to get the highest value from both of the compared objects (this BigInteger and BigInteger val).
max()方法用于从两个比较对象(此BigInteger和BigInteger val)获得最大值 。
max() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
max()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
max() method does not throw an exception at the time of returning maximum.
max()方法在返回最大值时不会引发异常。
Syntax:
句法:
public BigInteger max(BigInteger val);
Parameter(s):
参数:
BigInteger val – represents the object to compare with this object for finding maximum.
BigInteger val –表示要与该对象进行比较以找到最大值的对象。
Return value:
返回值:
The return type of this method is BigInteger, it returns the maximum in anyone of the both compared objects.
此方法的返回类型为BigInteger ,它返回两个比较对象中任何一个的最大值。
Example:
例:
// Java program to demonstrate the example // of BigInteger max(BigInteger val) method of BigIntegerimport java.math.*;public class MaxOfBI { public static void main(String args[]) { // Initialize two variables str1 and str2 String str1 = "100"; String str2 = "80"; // Initialize two BigInteger objects BigInteger b_int1 = new BigInteger(str1); BigInteger b_int2 = new BigInteger(str2); // Display b_int1 and b_int2 System.out.println("b_int1: " + b_int1); System.out.println("b_int2: " + b_int2); // returns the BigInteger that holds the maximum // value in both of the compared object // i.e. 100.max(80) it returns 100 BigInteger max_val = b_int1.max(b_int2); System.out.println("b_int1.max(b_int2): " + max_val); }}
Output
输出量
b_int1: 100b_int2: 80b_int1.max(b_int2): 100
翻译自:
转载地址:http://mivzd.baihongyu.com/