Conversions Worksheet Answers

   1.  s promoted to int to add with 1 (since integer literal is an int)
       i set to 26

   2.  i multiplied by 2 to get 30, then the result is widened to a float
       f set to 30.0

   3.  compiler error because of narrowing, trying to store float value in int

   4.  cast creates value of f narrowed to int, which is 2, then 2 is added to that value
       i set to 4

   5.  2 is promoted to double then that value (2.0) is multiplied by d to get 0.5
       the result is cast to int to get 0
       i set to 0

   6.  i and 1 are promoted to float, then expression evaluated to get 38.5 as a float
       expression value widened to double
       d set to 38.5

   7.  compiler error because of narrowing, trying to store double value in a float

   8.  compiler error because of narrowing, trying to store int value in a short

   9.  compiler error because of narrowing, trying to store double value in a float

   10. int constant 5 is cast to short
       s is set to 5

   11. f is set to the float constant 3.14

   12. double constant 3.14 is cast to float
       f is set to 3.14

   13. m is set to the double constant 12

   14. compiler error because of narrowing, trying to store long value in an int

   15. m is cast to int then added to int constant 1 to get 51 as an int
       i is set to 51

   16. i + 1 is evaluated to get 16 as an int
       expression value widened to long
       m set to 16

Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2013