解题思路:
注意事项:
Math.sqrt(4)就是根号4的意思
参考代码:
import java.util.Scanner;
public class Main1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
double a = scanner.nextDouble();
double b=scanner.nextDouble();
double c=scanner.nextDouble();
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.print(String.format("%.2f",x1)+" ");
System.out.print(String.format("%.2f",x2));
} else {
System.out.print(String.format("%.2f",x2)+" ");
System.out.print(String.format("%.2f",x1));
}
}
}
0.0分
2 人评分