Description Of BigInteger:compareTo(BigInteger val)
The
java.math.BigInteger.compareTo(BigInteger val) compares this BigInteger with the specified BigInteger. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=).
Code Example Java BigInteger
import java.math.BigInteger;
public class BigIntegerExam {
public static void main(String[] args) {
BigInteger bi1 = new BigInteger("7");
BigInteger bi2 = new BigInteger("4");
// create int object
int res;
// compare bi1 with bi2
res = bi1.compareTo(bi2);
if (res == 0) {
System.out.println("Both values are equal");
} else if (res == 1) {
System.out.println("First Value is greater");
} else if (res == -1) {
System.out.println("Second value is greater");
}
}
}
ไม่มีความคิดเห็น :
แสดงความคิดเห็น