KnowledgeBoat Logo

Computer Science

What are the resulting data type of the following explicit conversions?

int i; float f; double d; short s; char c; byte b;

(a) (float) i/b + d;

(b) (int)f*d + c/s;

(c) (char)i + f - b*d;

(d) (double) (f/i)*c + s;

(e) (char) d + b/i - f*s;

Values & Data Types Java

15 Likes

Answer

(a) (float) i/b + d;

    (float) i/b + d
⇒ float / byte + double
⇒ float + double
⇒ double

(b) (int)f*d + c/s;

    (int)f*d + c/s
⇒ int * double + char / short
⇒ double + short
⇒ double

(c) (char)i + f - b*d;

    (char)i + f - b*d
⇒ char + float - byte * double
⇒ char + float - double
⇒ double

(d) (double) (f/i)*c + s;

    (double) (f/i)*c + s
⇒ (double) (float / int) * char + short
⇒ double * char + short
⇒ double + short
⇒ double

(e) (char) d + b/i - f*s;

    (char) d + b / i - f * s
⇒ char + byte / int - float * short
⇒ char + int - float
⇒ float

Answered By

9 Likes


Related Questions