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;
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
Related Questions
Predict the return data type of the following:
float m; p = m/3*(Math.pow(4,3)); System.out.println(p);
A non-primitive data type is also referred to as reference type. Explain Why?
Predict the return data type of the following:
int p; double q; r = p+q; System.out.println(r);
Explain the term type casting.