📄 fc.java
字号:
import javax.swing.JOptionPane;
public class Fc
{
public static void main(String args[])
{
double a;
double b;
double c;
String result;
a = Double.parseDouble(JOptionPane.showInputDialog("请输入参数a的值"));
b = Double.parseDouble(JOptionPane.showInputDialog("请输入参数b的值"));
c = Double.parseDouble(JOptionPane.showInputDialog("请输入参数c的值"));
if(a==0)
{
if(b==0)
{
result = "输入出现错误!";
}
else
{
result = "该方程有一个实数根:\nx="+Math.round(-c/b*1000)/1000.00;
}
}
else
{
double d;
d = b*b-4*a*c;
if(d==0)
{
double x;
x = Math.round(-b/2/a*1000)/1000.00;
result = "该方程有两个相等的实数根:\nx1=x2="+x;
}
else if(d>0)
{
double x1;
double x2;
x1 = Math.round((-b+Math.sqrt(d))/2/a*1000)/1000.00;
x2 = Math.round((-b-Math.sqrt(d))/2/a*1000)/1000.00;
result = "该方程有两个不相等的实数根:\nx1="+x1+"\nx2="+x2;
}
else
{
String x1;
String x2;
x1 = Math.round(-b/2/a*1000)/1000.00
+"+"
+Math.round(Math.sqrt(-d)/2/a*1000)/1000.00
+"i";
x2 = Math.round(-b/2/a*1000)/1000.00
+"-"
+Math.round(Math.sqrt(-d)/2/a*1000)/1000.00
+"i";
result = "该方程有两个不相等的复数根:\nx1="+x1+"\nx2="+x2;
}
}
JOptionPane.showMessageDialog(null, result, "结果", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -