简体   繁体   English

Math.abs()报告错误:找不到符号

[英]Math.abs() reporting error: cannot find symbol

I'm new to java and I'm trying to figure out how the Math functions work. 我是java的新手,我正在试图弄清楚数学函数是如何工作的。 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);" 当我尝试编译它时,jGRASP说,“Math.java:5:错误:找不到符号double x = Math.abs(4);”

You called your class Math , so the built-in java.lang.Math class can't be resolved. 您调用了Math类,因此无法解析内置的java.lang.Math类。 So Java thinks you're attempting to call your own abs method that doesn't exist. 所以Java认为你试图调用你自己的不存在的abs方法。

Call your class something else, or refer to Math.abs with a fully qualified class name: java.lang.Math.abs(4) . 将您的类称为其他类,或者使用完全限定的类名称引用Math.absjava.lang.Math.abs(4)

You could also try: 你也可以尝试:

public class MyTest {

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM