题目
题目描述
3.1(代数:解一元二次方程)
可以使用下面的公式求一元二次方程ax2+bx+c=0
r1 = (-b + Math.pow((Math.pow(b, 2) - 4 * a * c), 0.5)) / 2a
r2 = (-b - Math.pow((Math.pow(b, 2) - 4 * a * c), 0.5)) / 2*a
判断式:Math.pow(b, 2) - 4 * a * c
判断式>0则有两个根,=0一个根,<0显示"The equation has no real roots"
编写程序提示用户输入a b c的值,并显示基于判断式的结果
运行示例
Enter a, b, c: 1.0 3 1
The equation has two roots -0.381966 and -2.61803
Enter a, b, c: 1 2.0 1
The equation has one root -1.0
Enter a, b, c: 1 2 3
The equation has no real roots
破题
- 获取用户输入的a b c三个值
- 计算判别式
- 根据判别式结果分三种情况计算根值并输出
代码
import java.util.Scanner;
public class Test3_1 {
public static void m