Computer Science
What are the resulting data types 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
2 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
1 Like
Related Questions
Perform the following:
Assign the value "TEST" to a variable with the requisite data type.
Predict the return data type in the following expressions:
int p; double q;
r = p+q;Predict the return data type in the following expressions:
float m;
p = m/3*(Math.pow(4,3));What are the resulting data types, if the following implicit conversions are performed:
int i; float f; double d; char c; byte b;
(a) i + c/b;
(b) f/d + c*f;
(c) i + f - b*c;
(d) i/c + f/b;
(e) i + f- c + b/d;