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);
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...

## All 5 Replies

uh, and what was the question?

It prints
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, learning, and sharing knowledge.