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: Help with Quadratic forumla equation in java please.

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

    Default Help with Quadratic forumla equation in java please.

    I am in an introductory class of Java programming and our first assignment is to create a program that can compute -b +- √b^2 - 4ac / 2a. This is my first time doing anything with java and I'm rather lost on the if/else statement and doing the square roots. Any help with this would be greatly apperciated.

    So far this is all I have

    import java.util.Scanner;
    import javax.swing.JOptionPane;

    public class homework1
    {
    public static void main(String[] args)
    {
    //Display message

    double aceof = (double)
    double bceof = (double)
    double cceof = (double)

    System.out.print("Enter A")
    double aceof = input.nextDouble();
    System.out.print("Enter B")
    double bceof = input.nextDouble();
    System.out.print("Enter C")
    double cceof = input.nextDouble();

    if (aceof == 0)


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Help with Quadratic forumla equation in java please.

    Ok, well what specifically about the if/else statement is confusing? What are you needing to do?

    In JAVA, we have a very rich API. One notable class is the Math Class(Math (Java Platform SE 6)).

    In the Math Class, there is the following method:
    sqrt

    public static double sqrt(double a)

    Returns the correctly rounded positive square root of a double value. Special cases:

    * If the argument is NaN or less than zero, then the result is NaN.
    * If the argument is positive infinity, then the result is positive infinity.
    * If the argument is positive zero or negative zero, then the result is the same as the argument.

    Otherwise, the result is the double value closest to the true mathematical square root of the argument value.

    Parameters:
    a - a value.
    Returns:
    the positive square root of a. If the argument is NaN or less than zero, the result is NaN.

    Does that make sense?

Similar Threads

  1. 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
  2. help!! quadratic program
    By dscrudato21xo in forum What's Wrong With My Code?
    Replies: 14
    Last Post: October 18th, 2009, 05:13 PM