I need to use “hypot” method in my Android game however eclipse says there is no such a method. Here is my code:
import java.lang.Math;//in the top of my file
float distance = hypot(xdif, ydif);//somewhere in the code
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.
Firstly, you don’t need to import types in
java.langat all. There’s an implicitimport java.lang.*;already. But importing a type just makes that type available by its simple name; it doesn’t mean you can refer to the methods without specifying the type. You have three options:Use a static import for each function you want:
Use a wildcard static import:
Explicitly refer to the static method:
Also note that
hypotreturnsdouble, notfloat– so you either need to cast, or makedistanceadouble: