Results 1 to 4 of 4
Thread: Quadratic equation help please.
 10092012, 04:54 AM #1Member
 Join Date
 Oct 2012
 Posts
 2
 Rep Power
 0
Quadratic equation help please.
Hello all!
Just starting to learn java and I was wondering if someone could help me out with this error I keep on running into. The application that I want to create will allow the user to enter in 3 numbers (a.b.c) it will then enter those numbers into the quadratic equation and read the user all of the roots.
Code:
import java.util.Scanner;
import java.lang.Math;
public class quadtraticEquation
{
public static void main(String[] args)
{
double b;
double a;
double c;
double root1;
double root2;
Scanner input = new Scanner(System.in);
System.out.print("Enter the value for a: ");
a = input.nextDouble();
System.out.print("Enter the value for b: ");
b = input.nextDouble();
System.out.print("Enter the value for c: ");
c = input.nextDouble();
root1 = ((b(b2sqrt(a,2)*sqrt(c,2))/2*a));
System.out.println(root1);
root2 = ((b+(b2sqrt(a,2)*sqrt(c,2))/2*a));
System.out.println(root2);
}
}
I rearranged the quadratic equation so that b^24ac wasn't all included in the square root.
I am using BlueJ as my compiler and the error that I keep running into is "cannot find symbol  method sqrt(double,int).
The error always occurs in my formula for the square root.

Re: Quadratic equation help please.
There is no method sqrt. You have to call it by its full name, Math.sqrt(...).
 10092012, 06:03 AM #3Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,703
 Rep Power
 13
Re: Quadratic equation help please.
And also read the API documentation for Math.sqrt() paying attention to the number and type of arguments it takes. If you don't use the right number of arguments (of the right sort) the compiler is still going to complain about not being able to find the method.
I rearranged the quadratic equation so that b^24ac wasn't all included in the square root.
The most straight forward approach is to evaluate that expression (once and reuse it for both roots, checking that it's nonnegative).
 10092012, 01:36 PM #4Member
 Join Date
 Oct 2012
 Posts
 2
 Rep Power
 0
Similar Threads

Quadratic Equation Code Question
By meangrant in forum New To JavaReplies: 5Last Post: 10312010, 04:22 AM 
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, 06:35 PM 
Quadratic Equation
By jpnym15 in forum New To JavaReplies: 4Last Post: 11122008, 04:29 AM 
Help with quadratic equation in java
By paul in forum New To JavaReplies: 1Last Post: 07252007, 08:23 PM
Bookmarks