Parse decimal string to create BigInteger in Java

karthikeya Boyini
Published on 20-Dec-2018 12:48:17
To parse the decimal string to create BigInteger, just set the decimal string in the BigInteger.Here is our BigInteger.BigInteger one; String decStr = "687879"; one = new BigInteger(decStr);Let us see another example −Example Live Demoimport java.math.*; public class Demo {    public static void main(String[] args) {       BigInteger ... Read More

Parse Octal string to create BigInteger in Java

Samual Sam
Published on 20-Dec-2018 12:45:17
To parse the octal string to create BigInteger, use the following BigInteger constructor and set the radix as 8 for Octal −BigInteger(String val, int radix)This constructor is used to translate the String representation of a BigInteger in the specified radix into a BigInteger.In the below example, we have set the ... Read More

Java Program to retrieve the current bits in a byte array in two’s-complement form

karthikeya Boyini
Published on 20-Dec-2018 12:42:04
Use the toByteArray() method to return a byte array containing the two's-complement representation of this BigInteger. The byte array will be in big-endian byte-order: the most significant byte is in the zeroth element.The following is an example to retrieve the current bits in a byte array in two’s-complement form.Example Live Demoimport ... Read More

Format Month in MM format in Java

Samual Sam
Published on 20-Dec-2018 12:37:44
The MM format is for months in two-digits 01, 02, 03, 04, etc. Here, we will use the following.SimpleDateFormat("MM");Let us see an example −// displaying month in MM format SimpleDateFormat simpleformat = new SimpleDateFormat("MM"); String strMonth = simpleformat.format(new Date()); System.out.println("Month in MM format = "+strMonth)Above, we have used the SimpleDateFormat ... Read More

Make the first letter caps and the rest lowercase in Java

karthikeya Boyini
Published on 20-Dec-2018 12:32:04
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

Left pad a String in Java with zeros

Samual Sam
Published on 20-Dec-2018 12:28:52
The following is our string −String str = "Tim";Now take a StringBuilder object −StringBuilder strBuilder = new StringBuilder();Perform left padding and extend the string length. We have set it till 20, that would include the current string as well. The zeros that will be padded comes on the left. Append ... Read More

Left pad an integer in Java with zeros

karthikeya Boyini
Published on 20-Dec-2018 12:25:00
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

Left pad a String with spaces (' ') in Java

Samual Sam
Published on 20-Dec-2018 12:20:32
Let us see an example first to understand how a string looks with left padding −demotext //left padding with spaces 0000000demotext //left padding with 7 zerosThe following is our string −String str = "Jack";Now take a StringBuilder object −StringBuilder strBuilder = new StringBuilder();Perform left padding and extend the string length. ... Read More

Left pad a String with a specified character in Java

karthikeya Boyini
Published on 20-Dec-2018 12:16:25
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

Java Program to implement andNot operation on BigInteger

Samual Sam
Published on 20-Dec-2018 12:10:10
TheBigInteger.andNot(BigInteger val) returns a BigInteger whose value is (this & ~val). This method, which is equivalent to and(val.not()), is provided as a convenience for masking operations. This method returns a negative BigInteger if and only if this is negative and val is positive. Here, “val” is the value to be ... Read More
Advertisements