Java 程序来实现 BigInteger 上的 OR 运算
TheBigInteger.or(BigInteger val) 返回一个 BigInteger,其值为 (this | val)。此方法当且仅当 this 或 val 为负数的情况下才返回一个负 BigInteger。
在此,“val”是要用此 BigInteger 进行 OR 运算的值。
下面是一个示例 −
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger one, two, three;
one = new BigInteger("6");
two = one.or(one);
System.out.println("Result (or operation): " +two);
}
}输出
Result (or operation): 6
让我们看另一个示例 −
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger bi1, bi2, bi3;
bi1 = new BigInteger("9");
bi2 = new BigInteger("16");
bi3 = bi1.or(bi2);
String str = "OR operation on " + bi1 +" and " + bi2 + " gives " +bi3;
System.out.println( str );
}
}输出
OR operation on 9 and 16 gives 25
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP