Java Program to check for Integer Overflow

Checking for Integer Overflow means adding a value to the maximum value. For Integer, we will increment by 1 to the Integer.MAX_VALUE. On incrementing, an error won’t be visible. However, the output will be Integer.MIN_VALUE.

Maximum value of Integer is 231 – 1 i.e.

Minimum value of Integer is 232 i.e.

Example

Following is an example to check for Integer Overflow:

Output

On incrementing MAX_VALUE, it results in MIN_VALUE for Integer type in Java as shown above. Java handles overflow accordingly for Integer type.

Java Program to convert decimal to binary
Java Program for Minimum and Maximum values of datatype int
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading