jQuery in Action, 2nd edition*
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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()