This code I have written to convert double into int getting an exception.
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot cast from Double to int
This is my code
Double d = 10.9;
int i = (int)(d);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Doubleis a wrapper class on top of the primitivedouble. It can be cast todouble, but it cannot be cast tointdirectly.If you use
doubleinstead ofDouble, it will compile:You can also add a cast to
doublein the middle, like this: