java - 为什么使用 Math.sqrt() 和 Math.pow() 方法时会出现 "can' t find 符号?

标签 java

在读取 Math.sqrt 的行时,我在 NetBeans 上不断收到错误,指出“错误,找不到符号”和Math.pow ,而且我完全不知道是什么导致弹出这个确切的错误。

我知道 Math java中的类是预先安装到编译器中的。最重要的是,即使我确实尝试导入 Math 文件夹,系统也会提示我在 import java.lang.Math; 上出现第二个错误。 ,它只是表示它已经处于 Activity 状态,无需导入。我尝试使用“构建和清理”功能来修复问题,并关闭“保存时编译”功能,这两种方法对 Netbeans 中的错误没有影响。

import java.util.Scanner;

import java.text.DecimalFormat;

public class Math {

    public static void main(String[] args) {       

        double input, square, sqrt, cube;

        DecimalFormat fmt = new DecimalFormat("0.###");

        Scanner scan = new Scanner(System.in);


        System.out.print("Welcome to the basic mathematics computation program.  What number would you like to test today? ");
        input = scan.nextFloat();

        sqrt = Math.sqrt(input);
        square = Math.pow(input, 2);
        cube = Math.pow(input, 3);

        System.out.println("The program is complete! \n"
            + "The square of your number is " + fmt.format(square) + ", \n"
            + "the cube of your number is " + fmt.format(cube) + ", \n"
            + "and the square of your number is " + fmt.format(sqrt) + ".");
    }


}

期望程序能够计算并打印任何正输入值的平方根、平方和立方,四舍五入到最接近的千分之一。但是,错误消息阻止任何输出。

最佳答案

这是因为你的类(class)有相同的名称:“Math”。为了避免混淆,请使用全名:java.lang.Math.pow() 或更改类的名称。

关于java - 为什么使用 Math.sqrt() 和 Math.pow() 方法时会出现 "can' t find 符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57846612/

相关文章:

java - 如何在一个PrepareStatement (sqlite) 中使用Array 或List<>

java - 找不到符号类 Intent

java - Libgdx:如何在X轴上移动对象而不重叠?

java - 使用模式在java中搜索和替换字符串

java - 由于先前的错误,Spring Web 应用程序无法启动

c# - C#中的Java内部类

java - 如何使用Java从属性文件中选取一组随机值?

java - 上传文件不调用onFinish()方法

Java ZipInputStream 异常在代码执行之前抛出

java - Jmeter - future 时间戳