解题思路:
import java.text.DecimalFormat; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); double a = input.nextDouble(); double b = input.nextDouble(); double c = input.nextDouble(); Calculate(a, b, c); } public static void Calculate(double a, double b, double c) { double x1 = (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a); double x2 = (-b - Math.sqrt(b * b - 4 * a * c)) / (2 * a); DecimalFormat df = new DecimalFormat("######0.00"); if (b * b - 4 * a * c!=0) { if (x1>x2) // 判断一定要准确; { System.out.println(df.format(x1)+" "+df.format(x2)); }else { System.out.println(df.format(x2)+" "+df.format(x1)); } } if (b * b - 4 * a * c==0) { System.out.println(df.format(x1)); } } }
注意事项:
参考代码:
0.0分
0 人评分
大神老白 (C语言代码)浏览:768 |
printf基础练习2 (C语言代码)浏览:605 |
字符串对比 (C语言代码)浏览:1469 |
拆分位数 (C语言代码)浏览:1361 |
【出圈】 (C语言代码)浏览:824 |
求组合数 (C语言代码)浏览:1206 |
Cylinder (C语言描述,蓝桥杯)浏览:1279 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:536 |
1035 题解浏览:875 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:536 |