# Quadratic Equation Code Question

• 10-31-2010, 03:10 AM
meangrant
Quadratic Equation Code Question
Hi, I'm taking a computer science course and I hit a brick wall with my program. Something is wrong and I have no idea how to fix it.

import java.util.*;
import static java.lang.Math.*;
{

Scanner input= new Scanner(System.in);
public static void main(String[] args)
{
//Declare variables
double a=0.0; double b=0.0; double c=0.0;double d=0.0;double e=0.0;
double r1=0.0; double r2=0.0;

//Ask user for input
System.out.println("Please input 3 doubles to solve the Quadratic formula.");
//Read and store a,b,c
a=console.nextDouble();
b=console.nextDouble();
c=console.nextDouble();
//If a=0, make program quit
if (a==0){
System.out.println("The input for a cannot be zero.");
//Else compute d
}else{
b=Math.pow(b,2);
d=(b-4*a*c);
//If d<0 no solution
if (d<0){
System.out.println("The disciminant cannot be less than 0.");
//Else if d=0, one solution.
}else if (d==0){
r1=(-b/2*a);
System.out.println("The single root is "+r1);
//If discriminant fits requirements, find the two roots.
}else{
e=Math.sqrt(d);
r1=((-b+e)/2*a);
r2=((-b-e)/2*e);
System.out.println("The first root is " +r1);
System.out.println("The second root is " +r2);
}
}
}
}

The error messages I receive are:

QuadraticEquationGEM.java:32: cannot find symbol
symbol : variable console
a=console.nextDouble();
^
QuadraticEquationGEM.java:33: cannot find symbol
symbol : variable console
b=console.nextDouble();
^
QuadraticEquationGEM.java:34: cannot find symbol
symbol : variable console
c=console.nextDouble();
^
3 errors
• 10-31-2010, 03:33 AM
Fubarable
You are using a variable called console but never declare it, never initialize it. If this is supposed to be a Scanner variable, you will want to check your notes and texts to see how it is declared and used.
• 10-31-2010, 03:46 AM
meangrant
Alright, I switched input to Scanner, thank you for the help.

Now, I have a different problem where

found : double
required: boolean
if (a=0.0){

found : double
required: boolean
}else if (d=0.0){
^
2 errors
• 10-31-2010, 04:21 AM
Fubarable
There's a big difference between the assignment operator, =, and the equals operator, ==. Does this now make sense?

Luck!
• 10-31-2010, 04:21 AM
meangrant
nm, I got it fixed.
• 10-31-2010, 04:22 AM
meangrant
Thank you for the help!