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

1. 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. 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?