1 import javax.swing.JOptionPane;
2 public class TheDirection {
3 public static void main(String[] args){
4 double a,b,c,t,r1,r2;
5 String number;
6 int messageType=JOptionPane.INFORMATION_MESSAGE;
7 number=JOptionPane.showInputDialog(null,"输入a");
8 a=Double.parseDouble(number);
9 number=JOptionPane.showInputDialog(null,"输入b");
10 b=Double.parseDouble(number);
11 number=JOptionPane.showInputDialog(null,"输入c");
12 c=Double.parseDouble(number);
13 t = b*b-4*a*c;
14 if(t>0){
15 r1 = (-b+Math.pow(t,0.5))/(2*a);
16 r2 = (-b-Math.pow(t,0.5))/(2*a);
17 String message="The equation has two roots " + r1 + " and "+ r2;
18 JOptionPane.showMessageDialog(null,message,"result",messageType);
19 }
20 else if(t==0){
21 r1 = (-b+Math.pow(t,0.5))/(2*a);
22 String message="The equation has one roots " + r1;
23 JOptionPane.showMessageDialog(null,message,"result",messageType);
24 }
25 else{
26 String message="The equation has no real roots ";
27 JOptionPane.showMessageDialog(null,message,"result",messageType);
28 }
29
30 }
31 }