Java程序在BigInteger上实现NOT操作
BigInteger.not()方法返回一个BigInteger,其值为(〜this)。当且仅当此BigInteger为非负值时,此方法才返回负值。
以下是一个例子-
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger one, two, three;
one = new BigInteger("6");
two = one.not();
System.out.println("Result (not operation): " +two);
}
}输出结果
Result (not operation): -7
让我们看另一个例子-
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger bi1, bi2, bi3, bi4;
bi1 = new BigInteger("9");
bi2 = new BigInteger("-12");
bi3 = bi1.not();
bi4 = bi2.not();
String str1 = "Result of not operation on " + bi1 +" gives " +bi3;
String str2 = "Result of not operation on " + bi2 +" gives " +bi4;
System.out.println( str1 );
System.out.println( str2 );
}
}输出结果
Result of not operation on 9 gives -10 Result of not operation on -12 gives 11
热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短