Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Quadratic formula

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Quadratic formula

    Hi I don't know if I am taking the wrong approach with this as I have just started to learn programming in the book I am teaching myself from it said how would you write the following arithmetic expression with it being the quadratic formula but only the plus part of it in the plus or minus..
    package javalearning;
    import java.util.Scanner;
     
    public class QuadraticFormula {
     
        public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        System.out.print("Enter value for B: ");
        double B = input.nextDouble();
        System.out.print("Enter value for A: ");
        double A = input.nextDouble();
        System.out.print("Enter value for C: ");
        double C = input.nextDouble();
        double negativeOfB = -B;
        double bPowerOfTwo = Math.pow(B, 2);
        double squareRoot = Math.sqrt(bPowerOfTwo - (4 * A * C));
        double Dividend = negativeOfB + squareRoot;
        double Divisor = 2 * A;
        double Answer = Dividend / Divisor;
        System.out.println("The answer to the Quadratic Formula where B is " + 
                B + " A is " + A + " and C is " + C + " is " + Answer + ".");
     
        }
    }

    The result for a problem I know the answer to is 5
    run:
    Enter value for B: -3
    Enter value for A: -10
    Enter value for C: 1
    The answer to the Quadratic Formula where B is -3.0 A is -10.0 and C is 1.0 is -0.5.
    BUILD SUCCESSFUL (total time: 11 seconds)
    Any and all help is very appreciated Thank you ahead of time side note I am new to this so If i posted this in a wrong way please let me know and I will fix it


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Quadratic formula

    What equations.formulas are you having problems writing java code for?
    There are many statements in the code that compute values. Which one of them is not computing the correct value? If you can't easily see, add a println() statement after every statement and print out the results. Compare that with the results you have computed manually. If you can't resolve the program's results for a statement with your results, copy the print out and paste it here and explain why you think there is a problem.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Quadratic Probing
    By Herah in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 15th, 2012, 01:12 PM
  2. quadratic equation solver help!
    By overlord in forum Algorithms & Recursion
    Replies: 2
    Last Post: October 20th, 2011, 11:39 AM
  3. Help with Quadratic forumla equation in java please.
    By taylor6132 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 27th, 2010, 07:27 PM
  4. How to handle quadratic roots that don't exist?
    By kairojya in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 28th, 2009, 12:21 PM
  5. help!! quadratic program
    By dscrudato21xo in forum What's Wrong With My Code?
    Replies: 14
    Last Post: October 18th, 2009, 05:13 PM