Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Math.PI comes up with cannot find symbol error

  1. Jun 26, 2011 #1
    Math.PI comes up with "cannot find symbol" error

    class Pi {
    public static void main (String[] args) {



    float radius=Float.parseFloat(args[0]);
    float shortPi=(float) Math.PI;



    float circ= shortPi *(radius+radius);
    float area= shortPi *(radius*radius);

    System.out.print("with Pi commuted from " +Math.PI);
    System.out.println(" to " + shortPi + "...");
    System.out.println("A circle radius of " + circ + " cm");
    System.out.print("has a circumference of " +area+ "sq.cm");

    }}

    _______________________________________________________
    I get two "cannot find symbol" errors, both of which point to the use of Math.PI. Is there something else I need to do? Math.PI is suppose to be constant value worth 3.141592653589793
     
  2. jcsd
  3. Jun 26, 2011 #2

    DrGreg

    User Avatar
    Science Advisor
    Gold Member

    Re: Math.PI comes up with "cannot find symbol" error

    I don't know which programming language this is, but I suspect you need to put something at the start of your code to tell the compiler how to find the definition of "Math".
     
  4. Jun 26, 2011 #3

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    Re: Math.PI comes up with "cannot find symbol" error

    DrGreg: This is java. Math.PI is a part of java.lang, so no declaration is needed.

    UltimateSomni: It's been a long time since I did java, but the opening line looks wrong. IIRC, class Pi should be public class Pi.
     
  5. Jun 26, 2011 #4
    Re: Math.PI comes up with "cannot find symbol" error

    public class Pi leads to the same error in the command prompt

    It works for the IDE though.
     
    Last edited: Jun 26, 2011
  6. Jun 26, 2011 #5
    Re: Math.PI comes up with "cannot find symbol" error

    The problem is probably not your code. There's problems in there, but none of them should be causing that problem. Your IDE seems to be doing things correctly. I suspect there's something wrong with your setup on the command line.

    What that problem is, I haven't a clue, as I don't have enough information to figure it out. You could try manually setting your classpath or something like that. I would guess it generally can't find the java libraries.

    You might take a close look at what your IDE is using as a command line to launch the program.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook