• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

import java.question

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic