This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes abs() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "abs()" Watch "abs()" New topic
Author

abs()

neeraj
Greenhorn

Joined: Feb 18, 2000
Posts: 10
I am getting the error' Method abs() not found' error . when I compile the following code.
Please explain me why???
import java.lang.Math;
public class Testexam {
public static void main (String args []) {
double d = 12.56;
System.out.println(abs(d));
}
}

Thandapani Saravanan
Ranch Hand

Joined: Oct 17, 1999
Posts: 117
I think you must tell the compiler which class the method belongs to. Here it is Math and Math.abs(d) is how you call abs.
You don't have to import java.lang.Math here, it is done for you.


Saravanan
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
For static methods you need to include the name of the class.
Also, the <CODE>java.lang</CODE> package is automatically included in every Java program.


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abs()
 
Similar Threads
How do you extend a generic abstract class
Class cast
default constructor
abstract class and static methods
How it is possible abstract class have an object