import java.util.Scanner; public class Equation { public static void main(String[] args){ double r1,r2; Scanner input = new Scanner(System.in); System.out.println("请输入a,b,c的值:"); double a = input.nextDouble(); double b = input.nextDouble(); double c = input.nextDouble(); r1 = (-b + Math.pow((b * b - 4 * a *c), 0.5)) / (2 * a); r2 = (-b - Math.pow((b * b - 4 * a *c), 0.5)) / (2 * a); if (b * b - 4 * a * c < 0){ System.out.println("The equation has no real roots"); } else if (b * b - 4 * a * c == 0){ System.out.println("The root is " + r1); } else{ System.out.println("The root is " + r1 + r2); } } }
计算ax2+bx+c=0的根