0

I keep getting an error on NetBeans which states "error, cannot find symbol" when reading the lines for Math.sqrt and Math.pow, and I have absolutely no idea what is causing that exact error to pop up.

I know that the Math class in java is pre-installed into the compiler. On top of that, even when I did try to import the Math folder, I was prompted with a second error on import java.lang.Math;, which simply said it was already active, and didn't have to be imported. I've tried using the Build and Clean feature to try fixing the problem, as well as turning off the Compile on Save feature, both of which had no impact on the error in 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) + ".");
    }


}

The expect the program to be able to calculate and print the square root, square, and cube of any positive input value, rounded to the nearest thousandth. However, the error message is blocking any output.

Roddy of the Frozen Peas
  • 14,380
  • 9
  • 49
  • 99

1 Answers1

3

Its because you class has the same name: "Math". In order to avoid confusion use full name: java.lang.Math.pow() or change the name of your class.

Ernesto Campohermoso
  • 7,213
  • 1
  • 40
  • 51