# Thread: Can't find symbol

1. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## 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?

Java Code:

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);
}

}

}

2. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## Re: Can't find symbol

Sorted 4 of the errors, forgot the "int" before aValue...

Java Code:
public static void calculation(int a, int b, int c) {
int aValue = a;
int bValue = b;
int cValue = c;

3. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## Re: Can't find symbol

I still have 7 of the errors though

4. ## Re: Can't find symbol

Please post the full text of the error messages that show the lines where the errors are happening.

5. ## Re: Can't find symbol

There are no variables called aValue, bValue, cValue, plusAnswer and minusAnswer in your main method.
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.

6. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## Re: Can't find symbol

Originally Posted by PhQ
There are no variables called aValue, bValue, cValue, plusAnswer and minusAnswer in your main method.
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?

7. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## Re: Can't find symbol

There are more errors now, it can't find the variables...

Java Code:

public static void main(String[] args) {
int aValue, bValue, cValue;
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 {
}

}

}

8. ## 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()

There are more errors
Please copy and paste here the full text of the error messages.

9. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## Re: Can't find symbol

QuadraticSolver.java:21: error: cannot find symbol
aValue = a;
^
symbol: variable aValue
QuadraticSolver.java:22: error: cannot find symbol
bValue = b;
^
symbol: variable bValue
QuadraticSolver.java:23: error: cannot find symbol
cValue = c;
^
symbol: variable cValue
QuadraticSolver.java:25: error: cannot find symbol
if (aValue <= 0) {
^
symbol: variable aValue
QuadraticSolver.java:31: error: cannot find symbol
^
QuadraticSolver.java:32: error: cannot find symbol
^
6 errors

10. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## Re: Can't find symbol

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

11. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## Re: Can't find symbol

I tried this, it didn't work...

Java Code:

int aValue, bValue, cValue;

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 {
}

}

}

12. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## Re: Can't find symbol

did I do the Math.*** bit right?

13. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## Re: Can't find symbol

I get this with my (bad) adjustment:

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
System.out.println(plusAnswer + " and " + minusAnswer);
^
QuadraticSolver.java:16: error: non-static variable minusAnswer cannot be referenced from a static context
System.out.println(plusAnswer + " and " + minusAnswer);
^
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

14. ## 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:

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.

15. ## Re: Can't find symbol

Originally Posted by kkid
I get this with my (bad) adjustment:

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
System.out.println(plusAnswer + " and " + minusAnswer);
^
QuadraticSolver.java:16: error: non-static variable minusAnswer cannot be referenced from a static context
System.out.println(plusAnswer + " and " + minusAnswer);
^
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.
Last edited by PhQ; 09-09-2012 at 06:28 PM.

16. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## Re: Can't find symbol

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?

17. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## 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!

18. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## Re: Can't find symbol

This is my working code:

Java Code:

static int aValue, bValue, cValue;

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 {
}

}

}

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.

19. ## Re: Can't find symbol

Why should 'a' be positive?

kind regards,

Jo

20. Senior Member
Join Date
Jul 2012
Posts
245
Rep Power
5

## Re: Can't find symbol

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.

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.

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•