Results 1 to 4 of 4
Thread: Quadratic equation help please.
- 10-09-2012, 04:54 AM #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.
-
Re: Quadratic equation help please.
There is no method sqrt. You have to call it by its full name, Math.sqrt(...).
- 10-09-2012, 06:03 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
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.
Perhaps I'm missing something simple, but why?I rearranged the quadratic equation so that b^2-4ac 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).
- 10-09-2012, 01:36 PM #4
Member
- Join Date
- Oct 2012
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Quadratic Equation Code Question
By meangrant in forum New To JavaReplies: 5Last Post: 10-31-2010, 03:22 AM -
quadratic equation, problems that i can't solve
By kourai in forum New To JavaReplies: 2Last Post: 10-14-2010, 01:31 PM -
quadratic equation whith Rational class
By adamrain in forum New To JavaReplies: 8Last Post: 12-22-2009, 05:35 PM -
Quadratic Equation
By jpnym15 in forum New To JavaReplies: 4Last Post: 11-12-2008, 03:29 AM -
Help with quadratic equation in java
By paul in forum New To JavaReplies: 1Last Post: 07-25-2007, 08:23 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks