参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double a = scanner.nextDouble(); double b = scanner.nextDouble(); double c = scanner.nextDouble(); delta(a, b, c); } public static void delta(double a, double b, double c) { double delta = b * b - 4 * a * c; if(delta == 0) root1(a, b); else if(delta > 0) root2(a, b, c); else root3(a, b, c); } public static void root1(double a, double b) { System.out.printf("x1=%f x2=%f", -b / (2 * a)); } public static void root2(double a, double b, double c) { System.out.printf("x1=%f x2=%f", (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a), (-b - Math.sqrt(b * b - 4 * a * c)) / (2 * a)); } public static void root3(double a, double b, double c) { System.out.printf("x1=%.3f+%.3fi x2=%.3f-%.3fi", -b / (2 * a), Math.sqrt(4 * a * c - b * b) / (2 * a), -b / (2 * a), Math.sqrt(4 * a * c - b * b) / (2 * a)); } }
0.0分
5 人评分
【密码】 (C语言代码)浏览:350 |
字符串对比 (C语言代码)浏览:1469 |
简单的a+b (C语言代码)浏览:564 |
简单的a+b (C语言代码)浏览:385 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:544 |
哥德巴赫曾猜测 (C语言代码)浏览:2560 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:593 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:574 |
简单的a+b (C语言代码)浏览:529 |
字符串比较 (C语言代码)浏览:770 |