- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34494 Articles for Programming
173 Views
Use the BigInteger pow() method in Java to calculate the power on a BigInteger.First, let us create some objects.BigInteger one, two; one = new BigInteger("5");Perform the power operation and assign it to the second object −// power operation two = one.pow(3);The following is an example −Example Live Demoimport java.math.*; public class BigIntegerDemo { public static void main(String[] args) { BigInteger one, two; one = new BigInteger("5"); System.out.println("Actual Value: " +one); // power operation two = one.pow(3); System.out.println("Result: " +two); } }OutputActual Value: 5 Negated Value: 125
138 Views
Use the BigInteger negate() method in Java to negate a BigInteger.First, let us create an object −BigInteger one, two; one = new BigInteger("200");Negate the above and assign it to the second object −two = one.negate();The following is an example −Example Live Demoimport java.math.*; public class BigIntegerDemo { public static void main(String[] args) { BigInteger one, two; one = new BigInteger("200"); System.out.println("Actual Value: " +one); // negate two = one.negate(); System.out.println("Negated Value: " +two); } }OutputActual Value: 200 Negated Value: -200
101 Views
Use the BigInteger divide() method in Java to divide one BigInteger from another.First, let us create some objects.BigInteger one, two, three; one = new BigInteger("200"); two = new BigInteger("100");Divide the above and assign it to the third object −three = one.divide(two);The following is an example −Example Live Demoimport java.math.*; public class BigIntegerDemo { public static void main(String[] args) { BigInteger one, two, three; one = new BigInteger("200"); two = new BigInteger("100"); // division three = one.divide(two); String res = one + " / " + two + " = " +three; System.out.println("Result: " +res); } }OutputResult: 200 / 100 = 2
102 Views
Use the BigInteger subtract() method in Java to Subtract one BigInteger from another.First, let us create some objects −BigInteger one, two, three; one = new BigInteger("200"); two = new BigInteger("150");Subtract the above and assign it to the third object −three = one.subtract(two);The following is an example −Example Live Demoimport java.math.*; public class BigIntegerDemo { public static void main(String[] args) { BigInteger one, two, three; one = new BigInteger("200"); two = new BigInteger("150"); three = one.subtract(two); String res = one + " - " + two + " = " +three; System.out.println("Subtraction: " +res); } }OutputSubtraction: 200 - 150 = 50
381 Views
BigInteger class is used for big integer calculations which are outside the limit of the primitive data types. It provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.To multiply one BigInteger to another, use the BigInteger multiply() method.First, let us create some objects −BigInteger one, two, three; one = new BigInteger("2"); two = new BigInteger("8");Multiply the above and assign it to the third object −three = one.multiply(two);The following is an example −Example Live Demoimport java.math.*; public class BigIntegerDemo { public static void main(String[] args) { BigInteger one, ... Read More
139 Views
The java.math.BigInteger class provides operations analogues to all of Java's primitive integer operators and for all relevant methods from java.lang.Math.BigInteger class is used for big integer calculations which are outside the limit of the primitive data types. It provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.The following is an example that displays how we can work with BigInteger values.Example Live Demoimport java.math.BigInteger; public class BigIntegerDemo { public static void main(String[] args) { BigInteger bi1, bi2, bi3; // assign values to bi1, bi2 ... Read More
1K+ Views
BigInteger class provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.Let’s say the following is our byte array −byte[] arr = new byte[] { 0x1, 0x00, 0x00 };We will now convert them to BigInteger −BigInteger bInteger = new BigInteger(arr);The following is an example that creates BigInteger from a byte array in Java.Example Live Demoimport java.math.BigInteger; public class Demo { public static void main(String[] argv) throws Exception { byte[] arr = new byte[] { 0x1, 0x00, 0x00 }; BigInteger bInteger = new BigInteger(arr); System.out.println(bInteger); } }Output65536
402 Views
BigInteger class is used for big integer calculations which are outside the limit of the primitive data types. It provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.Firstly, set a long value −Long l = 198L;Now, create a new object for BigInteger and pass the above value −BigInteger bInteger = new BigInteger(l);The following is an example −Example Live Demoimport java.math.BigInteger; public class Demo { public static void main(String[] argv) throws Exception { Long l = 198L; BigInteger bInteger = BigInteger.valueOf(l); System.out.println(bInteger); } }Output198
107 Views
BigInteger class is used for big integer calculations which are outside the limit of the primitive data types. It provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.Firstly, set a string −String str = "268787878787687";Now, create a new object for BigInteger and pass the above string −BigInteger bInteger = new BigInteger(str);The following is an example −Example Live Demoimport java.math.BigInteger; public class Demo { public static void main(String[] argv) throws Exception { String str = "268787878787687"; BigInteger bInteger = new BigInteger(str); System.out.println(bInteger); } }Output268787878787687
159 Views
Enum in Java contains a fixed set of constants. They can have fields, constructors and method. It enhances type safety in Java.The following is an example wherein we are implementing Switch statement on Enumeration in Java −Example Live Demopublic class Demo { public static void main(String[] args) { Laptop l = Laptop.Inspiron; switch(l){ case Inspiron: System.out.println("Laptop for home and office use!"); break; case XPS: System.out.println("Laptop for the ultimate experience!"); break; case Alienware: System.out.println("Laptop for high-performance gaming"); break; } } } enum Laptop { Inspiron, XPS, Alienware; }OutputLaptop for home and office use!