English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Overflow occurs when the given value is greater than the maximum specified size of the data type. Overflow conditions may cause errors, or the implementation of programming languages can handle it automatically.
To display the overflow of data types, I take the float data type as an example. The float data type is a single precision32bit IEEE 754floating point.
The range of float data type is-
approximately ±3.40282347E+38F
The following program demonstrates overflow of data types in Java.
public class Demo { public static void main(String[] args) { System.out.println("Displaying Overflow... "); float val1 = 3.3976835E38f; System.out.println(val1 * 25f); } }
Output Result
Displaying Overflow... Infinity
In the above program, the float variable is initialized to.
float val1 = 3.3976835E38f;
After that, perform multiplication operations to check for overflow.
val1 * 25f;
Since it extends the maximum range, it will return 'Infinity' as the output.