Arithmetic Operators in Java

This post is to describe Arithmetic operators in Java.
List of Arithmetic Operators

Left to Right Associativity, Precedence
This is how importance given to automatic operators in Java
We know how to use int and String data types. Let us discuss how to use the remaining data types.
Float
Examples
Here X is described as float but after the = we used int data types but the actual answer will  while solving is again a float data type.
Since we are doing a division here we need to declare any one of the integer (or both) as float data type by placing .0f or .0F as shown in the first two figures.
We can also declare (float) after = sign as show in the figure 3.

Double
Just like float we need to declare any one of the integer (or both) as double data type by placing .0 as shown in below fig.

Post a Comment

0 Comments