• 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

Math

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could anybody tell me what's wrong with my code:

Why does the compiler give me an error:
RoundTest.java:7: cannot resolve symbol
symbol : method round (double)
location: class RoundTest
System.out.println(round(-1.5));
Thanks,
Jenny
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jenny,
The method round is a static method within the Math class. The proper way to call it would be like this:

That should take care of it, though.
By the way, thanks for including the error! It sure makes answering your question a lot easier.
Corey
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And since java.lang.* is imported automatically,

is the only necessary code. You can't import access to methods of classes using the import statement (so to speak). You can import access to classes that have methods. So, import the class, then invoke its static methods like this:
SomeClass.staticMethod()
or import the class and instantiate it to use its non-static methods:
new SomeClass.method()
reply
    Bookmark Topic Watch Topic
  • New Topic