You're re-declaring x
, so in the line
int x = (int)x
The x
on the right is not the same x
you previously declared. So its value defaults to 0 so (int)x
is 0. You normally wouldn't be able to have two x
variables. That's a thing jshell
lets you do, but in normal Java you couldn't do.
See this:
jshell> double x = 2.3
x ==> 2.3
jshell> int y = (int)x
y ==> 2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.