Results 1 to 6 of 6
Thread: Quadratic Equation Code Question
 10312010, 03:10 AM #1Member
 Join Date
 Oct 2010
 Posts
 4
 Rep Power
 0
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.*;
public class QuadraticEquationGEM
{
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=(b4*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=((be)/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
location: class QuadraticEquationGEM
a=console.nextDouble();
^
QuadraticEquationGEM.java:33: cannot find symbol
symbol : variable console
location: class QuadraticEquationGEM
b=console.nextDouble();
^
QuadraticEquationGEM.java:34: cannot find symbol
symbol : variable console
location: class QuadraticEquationGEM
c=console.nextDouble();
^
3 errors

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.
 10312010, 03:46 AM #3Member
 Join Date
 Oct 2010
 Posts
 4
 Rep Power
 0
Alright, I switched input to Scanner, thank you for the help.
Now, I have a different problem where
QuadraticEquationGEM.java:36: incompatible types
found : double
required: boolean
if (a=0.0){
QuadraticEquationGEM.java:46: incompatible types
found : double
required: boolean
}else if (d=0.0){
^
2 errors

There's a big difference between the assignment operator, =, and the equals operator, ==. Does this now make sense?
Luck!
 10312010, 03:21 AM #5Member
 Join Date
 Oct 2010
 Posts
 4
 Rep Power
 0
nm, I got it fixed.
 10312010, 03:22 AM #6Member
 Join Date
 Oct 2010
 Posts
 4
 Rep Power
 0
Similar Threads

quadratic equation, problems that i can't solve
By kourai in forum New To JavaReplies: 2Last Post: 10142010, 01:31 PM 
quadratic equation whith Rational class
By adamrain in forum New To JavaReplies: 8Last Post: 12222009, 05:35 PM 
Quadratic Equation
By jpnym15 in forum New To JavaReplies: 4Last Post: 11122008, 03:29 AM 
Quadratic GUI
By ryn21 in forum New To JavaReplies: 1Last Post: 10302008, 05:58 AM 
Help with quadratic equation in java
By paul in forum New To JavaReplies: 1Last Post: 07252007, 08:23 PM
Bookmarks