提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
二次方程求解器
/**from 时代Java - N o w J a v a . c o m**/ public class Main { public static void main(String[] arg) { double a, b, c; a = Math.sqrt(3.0); b = 2.0; c = -3.0; double delta = b * b - 4.0 * a * c; double root1, root2; root1 = (-b - Math.sqrt(delta)) / (2.0 * a); root2 = (-b + Math.sqrt(delta)) / (2.0 * a); System.out.println(root1); System.out.println(root2); System.out.println("Let us check the roots:"); System.out.println(a * root1 * root1 + b * root1 + c); System.out.println(a * root2 * root2 + b * root2 + c); } }