Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

import java.question

 
Justin Beattie
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Justin Beattie
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Justin Beattie
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heeeyy, yeah that`s working for me, and it makes sense too, thanks!!
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic