java.math.BigInteger.and(BigInteger val)返回一个BigInteger,其值为(this&val)。当且仅当this和val均为负数时,此方法才返回负数BigInteger。在此,“ val”是与此BigInteger进行“与”运算的值。
首先,创建BigInteger对象-
BigInteger one, two, three;
one = new BigInteger("12");
two = new BigInteger("6");对第一个和第二个对象执行AND操作-
three = one.and(two);
以下是一个例子-
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger one, two, three;
one = new BigInteger("12");
two = new BigInteger("6");
three = one.and(two);
System.out.println("Result: " +three);
}
}输出结果
Result: 4