Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Java Program to implement NOT operation on BigInteger
The BigInteger.not() method returns a BigInteger whose value is (~this). This method returns a negative value if and only if this BigInteger is non-negative.
The following is an example −
Example
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);
}
}
Output
Result (not operation): -7
Let us see another example −
Example
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 );
}
}
Output
Result of not operation on 9 gives -10 Result of not operation on -12 gives 11
Advertisements
