ok im trying to make a program for solving square equations by the general formula
but for some reason i cannot get it to solve the equation
so if anyone can help me
this is my code:

va= Integer.parseInt(a.getText());
vb= Integer.parseInt(b.getText());
vc= Integer.parseInt(c.getText());
vac=(4*va*vc);
vbc=(2*vb*vb);
vac2= (2*va);
vb2=(-1*vb);
raiz = Math.sqrt(vbc-vac);

vx1= ((vb2+raiz) / vac2);
vx2= ((vb2-raiz) / vac2);

x1p=String.valueOf(vx1);
x2p=String.valueOf(vx2);

x1.setText(x1p);
x2.setText(x2p);

Recommended Answers

All 3 Replies

Well, what problems are you having? What errors if any? Posting several lines of abbreviated variables and equations and saying "it's not right" is a bit vague.

vac=(4*va*vc);
vbc=(2*vb*vb);
....
raiz = Math.sqrt(vbc-vac);

The correct formula is b*b - 4*a*c. You write: vbc-vac = 2*vb*vb - 4*va*vc

thats right
thenk you javaAddict

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.