Math.PI comes up with cannot find symbol error

  • Thread starter Thread starter UltimateSomni
  • Start date Start date
  • Tags Tags
    Error Symbol
Click For Summary

Discussion Overview

The discussion revolves around a programming issue related to the use of Math.PI in a Java program, specifically addressing the "cannot find symbol" error encountered when compiling the code from the command line. The scope includes technical explanations and troubleshooting related to Java programming.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant reports encountering "cannot find symbol" errors related to Math.PI and questions if additional steps are needed for its use.
  • Another participant suggests that the programming language is unclear and implies that a declaration might be necessary to access Math.PI.
  • DrGreg identifies the language as Java and asserts that Math.PI is part of java.lang, indicating no declaration should be needed.
  • UltimateSomni proposes that the class declaration should be public class Pi, although this suggestion does not resolve the error.
  • A participant notes that using public class Pi still results in the same error when compiling from the command prompt, while it works in an IDE.
  • Another participant speculates that the issue may not be with the code itself but rather with the command line setup, suggesting potential problems with the classpath or Java libraries not being found.
  • This participant recommends checking the command line used by the IDE to launch the program for discrepancies.

Areas of Agreement / Disagreement

Participants express differing views on the source of the problem, with some attributing it to the code and others to the command line setup. No consensus is reached regarding the exact cause of the error.

Contextual Notes

There are indications of potential issues with the command line environment and classpath settings, but these remain unresolved. The discussion does not clarify the specific setup details that might be causing the errors.

UltimateSomni
Messages
62
Reaction score
0
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
 
Technology news on Phys.org


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".
 


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.
 


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

It works for the IDE though.
 
Last edited:


UltimateSomni said:
public class Pi leads to the same error in the command prompt

It works for the IDE though.

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.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 2 ·
Replies
2
Views
12K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K