int y = x;
System.out.print(y);
An error occurs because we name x a DDT (Double data type) and in the next line, we are switching it to an int value when claiming y = x. In order to fix this, we need to change the second line to double y = x to produce the output of 14.7
II) double x = 14.7;
int y = (int) x;
System.out.print(y);
The output produced is 14. we claim x to be a DDT and then in the next line we are saying make the integer value of y equal to the integer value of x. This is basically truncating the 14.7 to produce 14. The ddt is simply canceled due to (int) x;
III) int x = 14;
double y = x;
System.out.print(y);
This set of statements produces a value of 12.0. Since y = x , then y =14. However, it is calling for a ddt which makes it a double. With a double comes a decimal. A zero is added because we already declared the y = 14 so .0 applied.
Very good Ryan, all set here. The DDT acronym is creative, but let's not do that. : )
ReplyDeleteWe can just say things like, "oh yeah, variable n is a double."
Or
"variable count is an int."
15 XPs awarded for this completion.