Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(1) Assume that the following variable declarations are in effect: byte b; int i

ID: 3635491 • Letter: #

Question

(1)  Assume that the following variable declarations are in effect:

byte b;
int i;
short s;
long l;
float f;
double d;

For each of the following statements, indicate whether or not the statement is legal and compile without and error:

(a) b = s;
(b) s = b;
(c) i = s;
(d) i = f;
(e) f = s;
(f) d = l;

Give the type of each of the following expressions

(a) b + b 
(b) i + b
(c) s + l
(d) i + l
(e) f + d
(f) b + (int) b
(g) i + (float) b
(h) s + (int) l
(i) i + (byte) l
(j) f + (int) d


(2)  What are the values of the following expressions?  Assume that i has the value 3, j has the value 8, and x has the value 6.9.
(i and j are int variables; x is a double variable.)

(a) j % (int) x + i
(b) (double) (j/i)
(c) j / (double) i
(d) (double) j < (int) x + 2

(3)  What will be the value of c after the following statements have been executed:

double a = 3.5;
int b = 8;
double c = ((int) a + (double) b) / 2;

(4)  What will be the vaule of ch after the following statement has been executed:

char ch = (char) ('A' + 'z' - 'a');

// Please provide explanations for your answers

Explanation / Answer

1) (a) and (d) are illegal, rest are fine

I can answer all the questions but I'll do that only if you rate me a lifesaver first. I am doing this because I'll take the time to type the answer and then you don't rate.

So give the rating first, and I'll send the answers to your inbox.