-1

My code thus far : I dont know why in the world it doesnt see the Math.pow or let me do the exponents. Says that it

cannot find class Math symbol. Location : Package java.util

import java.util.Math;

 class Test {
        public static void main(String[] args)  {
            double result = Math.pow(4 , 2);
            System.out.printf("result");
        }
}
Phiter
  • 14,570
  • 14
  • 50
  • 84
Monte Dreyer
  • 13
  • 1
  • 4

5 Answers5

3

Math is located in java.lang which is imported by default, no need for the import statement.

You may also want to use System.out.println(result) instead of using printf which needs a format string to output your result.

class Test {
    public static void main(String[] args)  {
        double result = Math.pow(4 , 2);
        System.out.println(result);
    }
}      
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
1

Just a shot in the dark.... did you try import java.lang.Math?

Chad
  • 693
  • 5
  • 17
0

You'll need to use: import java.lang.Math.

Then to complete the task you're after.

for(int i=1; i<=11; i++){  
    System.out.println("Square is: " + Math.pow(i, 2));
    System.out.println("Cube is: " + Math.pow(i, 3));
}
Josh
  • 1,724
  • 13
  • 15
0

I know this is an old post but..

i don't see any answer to it so for anyone wondering I fixed this issue by changing the name of my file. Check to see if your file name is 'Math'. If it is, change it to something else like 'MathExample' and it should work.

0

As Grewal_Creator stated above, changing the class name and file from Math to MathExample fixed it. The name Math must be clashing with something else.