/** 安徽科技学院acm题
*/
Input
a,b,c的值。
Output
两个根x1和x2,其中x1>=x2。。结果保留两位小数
Sample Input
1 5 -2
Sample Output
0.37 -5.37
代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int a = cin.nextInt();
int b = cin.nextInt();
int c = cin.nextInt();
double x1 = (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a);
double x2 = (-b - Math.sqrt(b * b - 4 * a * c)) / (2 * a);
if (x1 > x2)
System.out.printf("%.2f %.2f",x1,x2);
else
System.out.printf("%.2f %.2f",x2,x1);
}
}