Evaluate the following expressions and state the type of each expression:
int a = 2; int b = 3; double c = 3.0;
1. b / 2.0
Type: ( double, boolean, decimal, int )?
Value: ( answer )?
2. b ! = 3
Type: ( double, boolean, decimal, int )?
Value: ( answer )?
3. a >= 2.0
Type: ( boolean, double, char, int )?
Value: ( answer )?
1 -->
b is an integer datatype and value 2.0 is float/double.
when we divide an integer with a flaot, we get answer in float/double.
so, b / 2.0 type will be -> double.
now, when we divide 3 by 2.0 we get 1.5.
Type -> double , Value -> 1.5
2-->
b != 3
this is checking if b is not equal to 3. It is comparing, so its type will be boolean.
now, we have value of b = 3, so,
b != 3 is not true, hence it will give value as 0 (false)
Type -> Boolean , Value -> 0
3-->
a >= 2.0
this is also checking if a is greater or equal to 2.0, so its type will be boolean.
now, we have value of a = 2, so,
a>=2.0 is true, hence it will give value as 1 (True)
Type -> Boolean, Value -> 1
Get Answers For Free
Most questions answered within 1 hours.