hi ....

i have written a programm which solves the math equation :

            x = -b +- square root of b ^ 2 - 4 (a)(c) all / 2(a)

programm is really short since am still a beginner
so heer it is :

import java.awt.*;
import java.applet.Applet;

public class MathEqu extends Applet
{
    InputField inputBox1;
    InputField inputBox2;
    InputField inputBox3;
    public void init() {
        inputBox1 = new InputField(5);
        inputBox2 = new InputField(5);
        inputBox3 = new InputField(5);
        inputBox1.initialise(0);
        inputBox2.initialise(0);
        inputBox3.initialise(0);
        add(inputBox1);
        add(inputBox2);
        add(inputBox3);
        repaint();
    }
    public void paint( Graphics g ) {
        double a = inputBox1.toInt();
        double b = inputBox2.toInt();
        double c = inputBox3.toInt();
        double first =((b*b)-4*(a)*(c))*1;
        double x1=(b*(-1))+(Math.sqrt(first))/(2*a);
        double x2=(b*(-1))-(Math.sqrt(first))/(2*a);
        g.drawString( "answer is " + x1, 10, 50 );
        g.drawString( "or answer is " + x2, 10, 70 );
    }
    public boolean action ( Event e, Object o ){
        repaint();
        return true;
    }
}

any help with that will be great
thanx...

uh, and what was the question?

It prints
" answer is NaN "
even when i enter another numbers in the input boxes
it dosent change

and sorry about not writing the Que. i think i was thinking alot about it, so ...

NaN is typically the result of a floating point divide by zero.
So look at what might cause that...

i think maybe you should check ur equation more closely

ok thanx , ill fix it .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.