Simple and small procedure for a secondary equation root

xiaoxiao2021-03-06  60

Import java.awt. *; import java.awt.event. *; import java.lang.math; import java.applet.applet; public class qiugen extends applet imports actionListener {

Textfield Test1, Test2, Test3, Test4, Test5; Double A, B, C; Double X1, X2; Button MyButton; Public Void Init () {Test1 = New TextField (2); test2 = new textfield (2); test3 = New TextField (2); test4 = new textfield (4); mybutton = new button ("calculation"); test5 = new textfield (50); add (test1); add (test2); add (Test3); add (MyButton Add (Test4); Add (Test5); MyButton.addActionListener (this);} public void actionPerformed (ActionEvent E) {if (E.GetSource () == mybutton {a = double.parsedouble (Test1.getText (TEST1.GETTEXT )); B = double.parsedouble (test2.gettext ()); c = double.parsedouble (test3.gettext ()); test4.settext (String.Valueof (b * b-4 * a * c)); if (B * B-4 * a * c> = 0 && a! = 0) {x1 = (- b java.lang.math.sqrt (b * b-4 * a * c)) / (2 * a); X2 = (- b-java.lang.math.sqrt (b * b-4 * a * c)) / (2 * a); test5.Settext ("root x1 =" x1 "root x2 =" x2 );

} Else if (a == 0) {x1 = x2 = -c / b; test5.Settext ("root x1 =" x1 "root x2 =" x2);} else if (b * b-4 * a * c <= 0) {x1 = java.lang.math.SQRT (4 * a * cb * b) / (2 * a); test5.settext ("root x1 =" b / (2 * a) " " String.Valueof (x1) "i" "x2 =" (- B / (2 * a)) " " String.Valueof (x1) "i");}}} }

转载请注明原文地址:https://www.9cbs.com/read-114072.html


New Post(0)