AcWing 658. 一元二次方程公式 - Java
原题链接
简单
作者:
KYCygni
,
2021-03-12 05:40:52
,
所有人可见
,
阅读 327
Java 代码
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
double a = cin.nextDouble();
double b = cin.nextDouble();
double c = cin.nextDouble();
if (a == 0)
System.out.println("Impossivel calcular");
else
{
double d = b * b - 4 * a * c;
if (d < 0)
System.out.println("Impossivel calcular");
else
{
a *= 2;
System.out.println("R1 = " + String.format("%.5f", (- b + Math.sqrt(d))/a));
System.out.println("R2 = " + String.format("%.5f", (- b - Math.sqrt(d))/a));
}
}
}
}