Samual Sam has Published 2492 Articles

Reverse an Integer in Java

Samual Sam

Samual Sam

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

1K+ Views

To reverse an integer in Java, try the following code −Example Live Demoimport java.lang.*; public class Demo {    public static void main(String[] args) {       int i = 239, rev = 0;       System.out.println("Original: " + i);       while(i != 0) {     ... Read More

Java Program to display printable characters

Samual Sam

Samual Sam

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

513 Views

To display printable characters, you need to work with the ASCII values from 32 to 127.With that, we are using the following, instead of System.out.println()System.out.write();The following displays all the printable characters.for (int i = 32; i < 127; i++) { System.out.write(i);Let us see the complete example.Example Live Demopublic class Demo { ... Read More

Java Program to subtract integers and check for overflow

Samual Sam

Samual Sam

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

891 Views

To check for Integer overflow, we need to check the Integer.MAX_VALUE with the subtracted integers result, Here, Integer.MAX_VALUE is the maximum value of an integer in Java.Let us see an example wherein integers are subtracted and if the result is more than Integer.MAX_VALUE, then an exception is thrown.The following is ... Read More

How to convert Decimal to Hexadecimal in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:50:01

5K+ Views

To convert decimal to hexadecimal, use any of the two methods i.e.Integer.toHexString() − It returns a string representation of the integer argument as an unsigned integer in base 16.Integer.parseInt() − It allows you to set the radix as well, for example, for hexadecimal set it as 16.Let us see an ... Read More

Convert string to a number in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 10:49:12

2K+ Views

To convert a string to a number in Java, use the Integer.parseInt() method. First, let use create a String and set value.String str = "45";Now, take an Integer and use the Integer.parseInt() method.Integer i = Integer.parseInt(str);Let us see the complete example.Example Live Demopublic class Demo {    public static void main( ... Read More

Java Program to convert boolean value to Boolean

Samual Sam

Samual Sam

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

3K+ 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

155 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

182 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

8K+ 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

227 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

Advertisements