-
BigInteger max() method: The max() method of the BigInteger returns the BigInteger whose value is the greater between current BigInteger and BigInteger passed as a parameter to the method. If both the values are equal, either may be returned.
There is a similar method compareTo() available on BigInteger class. The max() method is different than compareTo() in a way that in the compareTo() method we have to interpret the result while on the max method, the biggest BigInteger is already returned.
Syntax:
public BigInteger max(BigInteger val)
Parameters: The method accepts one parameter val which refers to the value with which the maximum is to be computed.
Return Value: The method returns the BigInteger whose value is the greater of this and val. If they are equal, either may be returned.
Below program illustrate max() method of BigInteger class.
import java.math.*;
public class GFG {
public static void main(String[] args) {
BigInteger biginteger= new BigInteger( "8976543245" );
BigInteger val= new BigInteger( "9248040402" );
BigInteger biggerInteger = biginteger.max(val);
String result = "Bigger Integer between " +biginteger+ " and "
+val+ " is " +biggerInteger;
System.out.println(result);
}
}
|
Output:
Bigger Integer between 8976543245 and 9248040402 is 9248040402
-
BigInteger min() method: The min() method of the BigInteger returns the BigInteger whose value is the lesser between current BigInteger and BigInteger passed as parameter to method. If both the values are equal, either may be returned.
There is a similar method compareTo() available on BigInteger class . The min() method different than compareTo() in a way that in the compareTo() method we have to interpret the result while on the min() method, the smallest BigInteger will be returned.
Syntax:
public BigInteger min(BigInteger val)
Parameters: The method accepts one parameter val which refers to the value with which the minimum is to be computed.
Return Value: The method returns the BigInteger whose value is the lesser of this and val. If the values are equal, either may be returned.
Below program illustrate min() method of BigInteger class.
import java.math.*;
public class GFG {
public static void main(String[] args) {
BigInteger biginteger= new BigInteger( "5782539631" );
BigInteger val= new BigInteger( "3592633823" );
BigInteger biggerInteger = biginteger.min(val);
String result = "lesser Integer between " +biginteger+ " and "
+val+ " is " +biggerInteger;
System.out.println(result);
}
}
|
Output:
lesser Integer between 5782539631 and 3592633823 is 3592633823
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!