6 Write the output of the following Java code and explain th
Solution
===========================================================
--------------
Answer:
--------------
z= 1 z1= 1.0 z2= 1.0 z3= 1.5
--------------------
Explanation:
--------------------
//Declare and assign values to x and y
int x =6, y=4, z;
float z1,z2,z3;
z = x/y;
=> z=6/4
=> z=1 (6/4 is a divident operation , coeffient value 1 is assignted to z of type integer)
=> Hence z value is 1
z1 = x/y;
=> z1=6/4
=> z1=1.0 (6/4 is a divident operation , coeffient value 1 is assignted to z1 of type float)
=> Hence z1 value is 1.0
z2 = (float)(x/y);
=> z1=(float) (6/4)
=> z1=1.0 (6/4 is a divident operation is performed return the result and then type casting performed on 1.0
and is assignted to z2 of type float)
=> Hence z2 value is 1.0
z3 = (float)x/y;
=> z1=(float) (6/4)
=> z1=1.5 (6/4 is a divident operation is performed and it is typecasted to float value 1.5
and is assignted to z3 of type float)
=> Hence z3 value is 1.0
===========================================================
