Karthikeya Boyini has Published 2383 Articles

Java Program to perform XOR operation on BigInteger

karthikeya Boyini

karthikeya Boyini

Updated on 29-Jun-2020 05:41:49

137 Views

The java.math.BigInteger.xor(BigInteger val) returns a BigInteger whose value is (this ^ val). This method returns a negative BigInteger if and only if exactly one of this and val are negative. Here, “val” is the value to be XOR'ed with this BigInteger.Firstly, create two BigInteger objects −one = new BigInteger("6"); two ... Read More

Java Program to implement OR operation on BigInteger

karthikeya Boyini

karthikeya Boyini

Updated on 29-Jun-2020 05:37:00

113 Views

TheBigInteger.or(BigInteger val) returns a BigInteger whose value is (this | val). This method returns a negative BigInteger if and only if either this or val is negative.Here, “val” is the value to be OR'ed with this BigInteger.The following is an example −Example Live Demoimport java.math.*; public class Demo {    public ... Read More

Left pad a String with a specified character in Java

karthikeya Boyini

karthikeya Boyini

Updated on 29-Jun-2020 05:34:29

172 Views

The following is our string −String str = "Amit";Now take a StringBuilder object −StringBuilder strBuilder = new StringBuilder();Set the character you want to pad with a string −Character ch = '^';Perform left padding and extend the string length to 5 (one for the additional character). The character that will be ... Read More

Left pad an integer in Java with zeros

karthikeya Boyini

karthikeya Boyini

Updated on 29-Jun-2020 05:32:26

1K+ Views

Let us see an example first to understand how an integer looks with left padding −888 //left padding with spaces 0000000999 //left padding with 7 zerosLet us see an example to left pad a number with zero −Example Live Demopublic class Demo {    public static void main(String[] args) {   ... Read More

Make the first letter caps and the rest lowercase in Java

karthikeya Boyini

karthikeya Boyini

Updated on 29-Jun-2020 05:30:03

833 Views

The following is an example −Example Live Demopublic class Demo {    public static void main(String[] args) {       String str = "laptop";       System.out.println("Original String = " +str);       // letter one       String strOne = str.substring(0, 1).toUpperCase();       // ... Read More

Create BigInteger via long type variable in Java

karthikeya Boyini

karthikeya Boyini

Updated on 29-Jun-2020 05:29:11

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 ... Read More

Working with BigInteger Values in Java

karthikeya Boyini

karthikeya Boyini

Updated on 29-Jun-2020 05:27:19

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 ... Read More

Subtract one BigInteger from another BigInteger in Java

karthikeya Boyini

karthikeya Boyini

Updated on 29-Jun-2020 05:26:03

101 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 ... Read More

Negate a BigInteger in Java

karthikeya Boyini

karthikeya Boyini

Updated on 29-Jun-2020 05:24:37

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 ... Read More

Performing Bitwise Operations with BigInteger in Java

karthikeya Boyini

karthikeya Boyini

Updated on 29-Jun-2020 05:22:38

212 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.Let us work with the testBit() method in Java to perform Bitwise operation. ... Read More

Advertisements