Discuss / Java / 练习答案

练习答案

Topic source
public class Main {    public static void main(String[] args) {        double a = 1.0;        double b = 3.0;        double c = -4.0;        // 求平方根可用 Math.sqrt():        // System.out.println(Math.sqrt(2)); ==> 1.414        // TODO:        double r = Math.sqrt(b*b-4*a*c);        double x=(-b+r)/2*a;        double y=(-b-r)/2*a;        // 求平方根可用 Math.sqrt():        // System.out.println(Math.sqrt(2)); ==> 1.414        System.out.println(r);        System.out.println(x);        System.out.println(y);        System.out.println("The function is "+x+"x^2"+y+"x"+c);        System.out.println(x==1 && y==-4? "测试通过":"测试失败");    }}

  • 1

Reply