• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abs()

 
neeraj
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 117
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic