# Thread: Quadratic equation help please.

1. Member
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-(b-2-sqrt(a,2)*sqrt(c,2))/2*a));
System.out.println(root1);
root2 = ((-b+(b-2-sqrt(a,2)*sqrt(c,2))/2*a));
System.out.println(root2);
}
}

I rearranged the quadratic equation so that b^2-4ac 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.

2. ## Re: Quadratic equation help please.

There is no method sqrt. You have to call it by its full name, Math.sqrt(...).

3. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
15

## 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^2-4ac wasn't all included in the square root.
Perhaps I'm missing something simple, but why?

The most straight forward approach is to evaluate that expression (once and reuse it for both roots, checking that it's nonnegative).

4. Member
Join Date
Oct 2012
Posts
2
Rep Power
0

## Re: Quadratic equation help please.

Originally Posted by pbrockway2
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.

Perhaps I'm missing something simple, but why?

The most straight forward approach is to evaluate that expression (once and reuse it for both roots, checking that it's nonnegative).

ok thanks ill try that! I guess i was just over-thinking it. My logic didn't make much sense. Thanks again!

#### Posting Permissions

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