# Can't find symbol

Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last
• 09-09-2012, 04:55 PM
kkid
Can't find symbol
I am writing a basic program to find the roots of a quadratic equation using the quadratic formula. However, I am getting the error in the title 11 times, can somebody please explain why?

Code:

```class Quadratic {         public static void main(String[] args) {         calculation(1, 1, -6);         System.out.println("The quadritic equation entered was:");         System.out.print(aValue + "x" + "\u00B2");         System.out.print(" + ");         System.out.print(bValue + "x");         System.out.print(" + ");         System.out.println(cValue);         System.out.println("The roots are:");         System.out.println(plusAnswer + " and " + minusAnswer);         }                 public static void calculation(int a, int b, int c) {                 aValue = a;                 bValue = b;                 cValue = c;                 if (aValue <= 0) {                 System.out.println("Only enter a positive number for a");                 return;                 }                 else {                 double plusAnswer = ((b*(-1))+sqrt(pow(b,2)-(4*a*c)))/(2*a);                 double minusAnswer = ((b*(-1))-(sqrt(pow(b,2)-(4*a*c))))/(2*a);                 }                 } }```
• 09-09-2012, 05:02 PM
kkid
Re: Can't find symbol
Sorted 4 of the errors, forgot the "int" before aValue...

Code:

```        public static void calculation(int a, int b, int c) {         int aValue = a;         int bValue = b;         int cValue = c;```
• 09-09-2012, 05:19 PM
kkid
Re: Can't find symbol
I still have 7 of the errors though
• 09-09-2012, 05:40 PM
Norm
Re: Can't find symbol
Please post the full text of the error messages that show the lines where the errors are happening.
• 09-09-2012, 05:40 PM
PhQ
Re: Can't find symbol
Also there is no method called pow() and sqrt() in your class. I am guessing you are trying to use the Math class for those methods.
• 09-09-2012, 05:58 PM
kkid
Re: Can't find symbol
Quote:

Originally Posted by PhQ
Also there is no method called pow() and sqrt() in your class. I am guessing you are trying to use the Math class for those methods.

do all variables have to be stated in the main method then?
can't I state them in the calculation method?

I have int before the aValue, bValue and cValue though, isn't that declaring them (and double before the "answer" variables)

Do I need Math.*** for the calc methods then?
• 09-09-2012, 06:04 PM
kkid
Re: Can't find symbol
There are more errors now, it can't find the variables...

Code:

```class Quadratic {         public static void main(String[] args) {         int aValue, bValue, cValue;         double plusAnswer, minusAnswer;         calculation(1, 1, -6);         System.out.println("The quadritic equation entered was:");         System.out.print(aValue + "x" + "\u00B2");         System.out.print(" + ");         System.out.print(bValue + "x");         System.out.print(" + ");         System.out.println(cValue);         System.out.println("The roots are:");         System.out.println(plusAnswer + " and " + minusAnswer);         }                 public static void calculation(int a, int b, int c) {                 aValue = a;                 bValue = b;                 cValue = c;                 if (aValue <= 0) {                 System.out.println("Only enter a positive number for a");                 return;                 }                 else {                 plusAnswer = ((b*(-1))+Math.sqrt(Math.pow(b,2)-(4*a*c)))/(2*a);                 minusAnswer = ((b*(-1))-(Math.sqrt(Math.pow(b,2)-(4*a*c))))/(2*a);                 }                 } }```
• 09-09-2012, 06:05 PM
Norm
Re: Can't find symbol
You need to define the variables where they are needed. Some are needed in several methods and those should be defined at the class level. Some are only used in a single method, those should be defined in the method and not in the class.

To call a class's static methods, code the name of the class dot methodname: Math.round()

Quote:

There are more errors
Please copy and paste here the full text of the error messages.
• 09-09-2012, 06:06 PM
kkid
Re: Can't find symbol
aValue = a;
^
symbol: variable aValue
bValue = b;
^
symbol: variable bValue
cValue = c;
^
symbol: variable cValue
if (aValue <= 0) {
^
symbol: variable aValue
^
^
6 errors
• 09-09-2012, 06:20 PM
kkid
Re: Can't find symbol
Quote:

Originally Posted by Norm
You need to define the variables where they are needed. Some are needed in several methods and those should be defined at the class level. Some are only used in a single method, those should be defined in the method and not in the class.

I use them two sets of variables in both methods, therefore I need to quote them at a class level?

How do I do this?
I have never done this before
• 09-09-2012, 06:21 PM
kkid
Re: Can't find symbol
I tried this, it didn't work...

Code:

```class Quadratic { int aValue, bValue, cValue; double plusAnswer, minusAnswer;         public static void main(String[] args) {         calculation(1, 1, -6);         System.out.println("The quadritic equation entered was:");         System.out.print(aValue + "x" + "\u00B2");         System.out.print(" + ");         System.out.print(bValue + "x");         System.out.print(" + ");         System.out.println(cValue);         System.out.println("The roots are:");         System.out.println(plusAnswer + " and " + minusAnswer);         }                 public static void calculation(int a, int b, int c) {                 aValue = a;                 bValue = b;                 cValue = c;                 if (aValue <= 0) {                 System.out.println("Only enter a positive number for a");                 return;                 }                 else {                 plusAnswer = ((b*(-1))+Math.sqrt(Math.pow(b,2)-(4*a*c)))/(2*a);                 minusAnswer = ((b*(-1))-(Math.sqrt(Math.pow(b,2)-(4*a*c))))/(2*a);                 }                 } }```
• 09-09-2012, 06:22 PM
kkid
Re: Can't find symbol
did I do the Math.*** bit right?
• 09-09-2012, 06:23 PM
kkid
Re: Can't find symbol

QuadraticSolver.java:9: error: non-static variable aValue cannot be referenced from a static context
System.out.print(aValue + "x" + "\u00B2");
^
QuadraticSolver.java:11: error: non-static variable bValue cannot be referenced from a static context
System.out.print(bValue + "x");
^
QuadraticSolver.java:13: error: non-static variable cValue cannot be referenced from a static context
System.out.println(cValue);
^
QuadraticSolver.java:16: error: non-static variable plusAnswer cannot be referenced from a static context
^
QuadraticSolver.java:16: error: non-static variable minusAnswer cannot be referenced from a static context
^
QuadraticSolver.java:21: error: non-static variable aValue cannot be referenced from a static context
aValue = a;
^
QuadraticSolver.java:22: error: non-static variable bValue cannot be referenced from a static context
bValue = b;
^
QuadraticSolver.java:23: error: non-static variable cValue cannot be referenced from a static context
cValue = c;
^
QuadraticSolver.java:25: error: non-static variable aValue cannot be referenced from a static context
if (aValue <= 0) {
^
QuadraticSolver.java:31: error: non-static variable plusAnswer cannot be referenced from a static context
^
QuadraticSolver.java:32: error: non-static variable minusAnswer cannot be referenced from a static context
^
11 errors
• 09-09-2012, 06:25 PM
Norm
Re: Can't find symbol
Where are the variables: aValue etc defined?

Why do you need them? You can use a,b,c directly in the method. You are using a,b,c here:

Quote:

it didn't work...
What did not work?
You need to post the full text of the error messages.

EDIT: I think we posted at the same time. You should try to put it all in one post and not continue to make changes and new posts.
• 09-09-2012, 06:26 PM
PhQ
Re: Can't find symbol
Quote:

Originally Posted by kkid

QuadraticSolver.java:9: error: non-static variable aValue cannot be referenced from a static context
System.out.print(aValue + "x" + "\u00B2");
^
QuadraticSolver.java:11: error: non-static variable bValue cannot be referenced from a static context
System.out.print(bValue + "x");
^
QuadraticSolver.java:13: error: non-static variable cValue cannot be referenced from a static context
System.out.println(cValue);
^
QuadraticSolver.java:16: error: non-static variable plusAnswer cannot be referenced from a static context
^
QuadraticSolver.java:16: error: non-static variable minusAnswer cannot be referenced from a static context
^
QuadraticSolver.java:21: error: non-static variable aValue cannot be referenced from a static context
aValue = a;
^
QuadraticSolver.java:22: error: non-static variable bValue cannot be referenced from a static context
bValue = b;
^
QuadraticSolver.java:23: error: non-static variable cValue cannot be referenced from a static context
cValue = c;
^
QuadraticSolver.java:25: error: non-static variable aValue cannot be referenced from a static context
if (aValue <= 0) {
^
QuadraticSolver.java:31: error: non-static variable plusAnswer cannot be referenced from a static context
^
QuadraticSolver.java:32: error: non-static variable minusAnswer cannot be referenced from a static context
^
11 errors

You need to make the variables above the main method static.
• 09-09-2012, 06:33 PM
kkid
Re: Can't find symbol
Quote:

Originally Posted by Norm
Where are the variables: aValue etc defined?

Why do you need them? You can use a,b,c directly in the method. You are using a,b,c here:

What did not work?
You need to post the full text of the error messages.

EDIT: I think we posted at the same time. You should try to put it all in one post and not continue to make changes and new posts.

Because a, b and c are just parameters of the calculation method and therefore I cannot have their values appear in main (I don't think - I'm new to this).

How do I make them static, do I just type static before them? (I am self-teaching and haven't came across this yet).
What does it mean if they're static?
• 09-09-2012, 06:39 PM
kkid
Re: Can't find symbol
UPDATE:

I tried putting "static" behind both of the variable declaration and I got no errors when compiling, I'm going to test it out now!

Thank you!
• 09-09-2012, 06:42 PM
kkid
Re: Can't find symbol
This is my working code:

Code:

```class Quadratic { static int aValue, bValue, cValue; static double plusAnswer, minusAnswer;         public static void main(String[] args) {         calculation(1, 1, -6);         System.out.println("The quadritic equation entered was:");         System.out.print(aValue + "x" + "\u00B2");         System.out.print(" + ");         System.out.print(bValue + "x");         System.out.print(" + ");         System.out.println(cValue);         System.out.println("The roots are:");         System.out.println(plusAnswer + " and " + minusAnswer);         }                 public static void calculation(int a, int b, int c) {                 aValue = a;                 bValue = b;                 cValue = c;                 if (aValue <= 0) {                 System.out.println("Only enter a positive number for a");                 return;                 }                 else {                 plusAnswer = ((b*(-1))+Math.sqrt(Math.pow(b,2)-(4*a*c)))/(2*a);                 minusAnswer = ((b*(-1))-(Math.sqrt(Math.pow(b,2)-(4*a*c))))/(2*a);                 }                 } }```

How do I print a 2 symbol though?
I searched online and it said to type \u00B2 but it just comes up with a filled in rectangle.
• 09-09-2012, 10:58 PM
JosAH
Re: Can't find symbol
Why should 'a' be positive?

kind regards,

Jo
• 09-12-2012, 05:04 PM
kkid
Re: Can't find symbol
Quote:

Originally Posted by JosAH
Why should 'a' be positive?

Thanks for pointing this out, I just didn't think it through much, I meant for it to be not zero, I'll change this now.

Quote:

Originally Posted by kkid
How do I print a 2 symbol though?
I searched online and it said to type \u00B2 but it just comes up with a filled in rectangle.

Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last