Java.math.BigInteger.max() Method

Advertisements


Description

The java.math.BigInteger.max(BigInteger val) returns the maximum of this BigInteger and val.

Declaration

Following is the declaration for java.math.BigInteger.max() method

public BigInteger max(BigInteger val)

Parameters

  • val - value with which the maximum is to be computed

Return Value

This method returns the BigInteger whose value is the greater of this and val. If they are equal, either may be returned.

Exception

  • NA

Example

The following example shows the usage of math.BigInteger.max() method

package com.tutorialspoint;

import java.math.*;

public class BigIntegerDemo {

public static void main(String[] args) {

	// create 3 BigInteger objects
        BigInteger bi1, bi2, bi3;

        bi1 = new BigInteger("123");
        bi2 = new BigInteger("1000");

        // assign the max value of bi1, bi2 to bi3
        bi3 = bi1.max(bi2);

	String str = "Maximum Value among " + bi1 + " and "+ bi2+" is "+ bi3;

        // print the maximum value
        System.out.println( str );
    }
}

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

Maximum Value among 123 and 1000 is 1000



Advertisements
Advertisements