Results 1 to 4 of 4
  1. #1
    proPAGANda is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default 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. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Quadratic equation help please.

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

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default 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. #4
    proPAGANda is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default Re: Quadratic equation help please.

    Quote Originally Posted by pbrockway2 View Post
    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!

Similar Threads

  1. Quadratic Equation Code Question
    By meangrant in forum New To Java
    Replies: 5
    Last Post: 10-31-2010, 04:22 AM
  2. quadratic equation, problems that i can't solve
    By kourai in forum New To Java
    Replies: 2
    Last Post: 10-14-2010, 02:31 PM
  3. quadratic equation whith Rational class
    By adamrain in forum New To Java
    Replies: 8
    Last Post: 12-22-2009, 06:35 PM
  4. Quadratic Equation
    By jpnym15 in forum New To Java
    Replies: 4
    Last Post: 11-12-2008, 04:29 AM
  5. Help with quadratic equation in java
    By paul in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 09:23 PM

Posting Permissions

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