ADVERTISEMENT
ADVERTISEMENT

Java BigInteger Class | max() Method with Example

BigInteger Class max() method: Here, we are going to learn about the max() method of BigInteger Class with its syntax and example.
Submitted by Preeti Jain, on May 11, 2020

BigInteger Class max() method

  • max() method is available in java.math package.
  • max() method is used to get the highest value from both of the compared objects (this BigInteger and 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() method does not throw an exception at the time of returning maximum.

Syntax:

    public BigInteger max(BigInteger val);

Parameter(s):

  • BigInteger val – represents the object to compare with this object for finding maximum.

Return value:

The return type of this method is BigInteger, it returns the maximum in anyone of the both compared objects.

Example:

// Java program to demonstrate the example 
// of BigInteger max(BigInteger val) method of BigInteger

import 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: 100
b_int2: 80
b_int1.max(b_int2): 100
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.