tut01_sol - EE3206/EE5805 Java Programming Application...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
EE3206/EE5805 Java Programming & Application Tutorial 1 - Solution Q1 a) It compiles, and x becomes 1 (byte). b) It compiles, and x becomes 127 (byte). c) Compilation error: “possible loss of precision; found : int; required : byte”. The byte primitive type stores values from -128 to 127. The value 128 cannot be stored in a byte variable. d) Compilation error: “possible loss of precision; found : int; required : char”. Though x is of type char, the expression (x + 1) evaluates to type int, and Java does not allow assignment an int value to a char variable without explicit casting. e) It compiles, and x becomes '1' (char). Initialization is sometimes different from assignment. Here the compiler computes '0' + 1 at compilation time to get '1', and initializes variable x to '1'. f) Compilation error: “possible loss of precision; found : int; required : char”. Here the expression (y + 1) is evaluated at run-time, and the result is of int type. Assigning an int value to a char variable without explicit casting is forbidden. g)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '07
  • CWTing
  • Harshad number, 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 0 2 4 6 8 10 12 14 16 18 0 3 6 9 12 15 18 21 24 27 0 4 8 12 16 20 24 28 32 36 0 6 12 18 24 30 36 42 48 54 0 7 14 21 28 35 42 49 56 63 0 8 16 24 32 40 48 56 64 72 0 9 18 27 36 45 54 63 72 81 g

{[ snackBarMessage ]}

Page1 / 3

tut01_sol - EE3206/EE5805 Java Programming Application...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online