Samual Sam has Published 2310 Articles

Java Program to convert boolean value to Boolean

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:48:25

5K+ Views

Use the valueOf() method to convert boolean value to Boolean. Firstly, let us take a boolean value.boolean val = false;Now, to convert it to Boolean object, use the valueOf() method.Boolean res = Boolean.valueOf(val);Let us now see the complete example to convert boolean value to Boolean.Example Live Demopublic class Demo {   ... Read More

Java Program to convert an Integer to a boolean specifying the conversion values

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:47:23

239 Views

To convert an Integer to a boolean, we have taken the following Integer objects.Integer one = 1; Integer two = 1; Integer three = 0;We have taken nested if-else statement to display the true or false values. Here, the value “one” is the same as “two” i.e. 1; therefore, the ... Read More

Underflow of DataTypes in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:46:06

294 Views

Underflow occurs when the given value is less than the maximum prescribed size of a data type. The underflow condition can result to an error or now the implementation of the programming language handles it on its own.To display underflow of datatypes, I have taken an example of double datatype. ... Read More

Integer Equals() method in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:45:13

10K+ Views

The Equals() method compares this object to the specified object. The result is true if and only if the argument is not null and is an Integer object that contains the same int value as this object.Let us first set Integer object.Integer val1 = new Integer(30); Integer val2 = new ... Read More

Java Program to convert octal number to decimal number

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:42:10

324 Views

Use the parseInt() method with the second parameter as 8 since it is the radix value. The parseInt() method has the following two forms.static int parseInt(String s) static int parseInt(String s, int radix)To convert octal to decimal, use the 2nd syntax and add radix as 8, since octal radix is ... Read More

Java Program to convert decimal integer to hexadecimal number

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:41:08

397 Views

Use the toHexString() method to convert decimal to hexadecimal. The method returns a string representation of the integer argument as an unsigned integer in base 16. The following characters are used as hexadecimal digits:0123456789abcdef.The following is the syntax.String toHexString(int i)It has only single parameter.i − This is an integer to ... Read More

Integer.rotateLeft() method in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:40:18

118 Views

The Integer.rotateLeft() method returns the value obtained by rotating the two's complement binary representation of the specified int value i left by the specified number of bits. The following is the syntax.int rotateLeft(int i, int distance)Here are the parameters.i − This is the int value.distance − This is the rotation ... Read More

Integer.reverseBytes() method in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:39:16

109 Views

The method returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified int value. Let us now see the syntax.int reverseBytes(int i)The following is the parameter.i − This is the int valueExample Live Demopublic class Demo {    public static void main(String ... Read More

Convert Java String Object to Boolean Object

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:38:28

2K+ Views

A string object can be created in Java using the string literal.String myStr = “Amit”;Another way to create a string object is using the new keyword.String myStr = new String("Hello!");We have used the first method to create a string object.String str = "true";Now, use the valueOf() method to convert String ... Read More

Read integers from console in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:36:26

20K+ Views

To read integers from console, use Scanner class.Scanner myInput = new Scanner( System.in );Allow a use to add an integer using the nextInt() method.System.out.print( "Enter first integer: " ); int a = myInput.nextInt();In the same way, take another input in a new variable.System.out.print( "Enter second integer: " ); Int b ... Read More

Advertisements