Hello everyone, first time beginner Java programmer with a question here (everyone says: BOO, lol). I am having a bit of trouble importing a math package into my class so i can perform simple math operation (sqrt, etc.). I am not too sure about the whole "import" thing either, i`m more of an #include kinda guy.. I tried: import java.lang.Math; and a few other combinations including my trusty kleene star *, but i keep seem to be getting a "Method sqrt(double) not found in class JustCalculator...". Anybody mind helping a poor lost Java kid find his way?
have a code snippet of what your problem is? ... and seeing as though you're a greenhorn on the JR, I'll give you a free hint: wrap your code snippets in the UBB [CODE] tags, it will preserve the whitespace and make it much easier to read .
Joined: Nov 28, 2001
yep, thanks! Here`s some snippet of my JustCalculator class. It`s basically, just a calculator, lol.
now the problem i am having is an error that says specifically:
and i know it has something to do with my import:
and finally, i don`t fully understand the concept of what the importing does... Thank you at least for reading!
Joined: Dec 10, 2001
In Java you import classes and packages, not methods. Your class has no method called sqrt - the Math class does. So, tell the compiler to use the Math class's method like this: Math.sqrt(...) Making sense? [ June 07, 2002: Message edited by: Dirk Schreckmann ]
Originally posted by Justin Beattie: and finally, i don`t fully understand the concept of what the importing does...
Importing classes lets you use short names for classes rather than the FULL class name. Try it out, you can remove the import statement and change your line to: java.lang.Math.sqrt(...) and it will work just the same.