Given:
int x = 10;
double d = -3.0;
boolean f = false;
1.
Why does the following remain a double after it is cast as an int… For the second one also, why does it output a float when defined as a long?:
(int) d / 2.0
(long) d * 2f
2.
Why does the first of the following print a string(?), and the latter a number?
"2" + x + 2
"3" + 3 * x
But then there is an error with the following:
"5" + i + 2
3.
Also, with the follwing, what is actually happening and what is the result?
d++ + d
4.
When Math.round is used, why does it convert the following double into a float, or are they the same thing?
Math.round(x / d)
Why does the following remain a double after it is cast as an int… For the second one also, why does it output a float when defined as a long?:
Because priority of cast
(int)operator is higher that/and*operators.You should read it like this:
Why does the first of the following print a string(?), and the latter a number?
I think it’s string in both casesm you must “read” this expressions like this:
But then there is an error with the following:
What is the error?
Also, with the follwing, what is actually happening and what is the result?
This is a sequence of actions:
When Math.round is used, why does it convert the following double into a float, or are they the same thing?
It converts to
long, because return type ofMath.round(double)islong