Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Math.abs() reporting error: cannot find symbol

Tags:

java

math

jgrasp

I'm new to java and I'm trying to figure out how the Math functions work. I can't figure out what I'm missing.

Here's the entire program:

    public class Math {

    public static void main(String args[])
      {
        double x = Math.abs(4); 
        System.out.println(x);   
      }
    }

When I try to compile it, jGRASP says, "Math.java:5: error: cannot find symbol double x = Math.abs(4);"

like image 868
rayden54 Avatar asked Jul 13 '26 21:07

rayden54


1 Answers

You called your class Math, so the built-in java.lang.Math class can't be resolved. So Java thinks you're attempting to call your own abs method that doesn't exist.

Call your class something else, or refer to Math.abs with a fully qualified class name: java.lang.Math.abs(4).

like image 124
rgettman Avatar answered Jul 16 '26 14:07

rgettman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!