使用Java创建程序来计算二次公式

时间:2015-09-30 20:29:48

标签: java

所以我正在研究这个项目。一切都很好,但数学不对。如果你输入全部2,s你应该得到结果(0,0),但我得到(1,-1)。如果我能得到一双新鲜的眼睛,让我知道我的计算错误在哪里,我做了什么,我真的很感激!

        System.out.println("Please enter the value for d: ");
        int d = IO.readInt();

    System.out.println("Please enter the value for f: ");
        int f = IO.readInt();

    System.out.println("Please enter the value for g: ");
        int g = IO.readInt();

    System.out.println("Please enter the value for m: ");
        int m = IO.readInt();

    System.out.println("Please enter the value for b: ");
        int b = IO.readInt();

    double y = (f - m);
    double u = (4*d*(g-b));
    double i = (2*d);
    double o = ((f+m)*(f+m));

  /*
         * x=(-(f-m)(+ or -)(sqrt((f-m)^2) - (4d(g-b))
         *                  2d
         * 
         * x=-b(+ or -)(sqrt((b^(2))-4ac))
         *              2a
         */

    double x = ((0-(y))+(Math.sqrt(o)-((u)))/(i));
    double x1 = ((0-(y))-(Math.sqrt(o)-((u)))/(i));

    IO.outputStringAnswer(x + " , " + x1);

1 个答案:

答案 0 :(得分:0)

检查o值,它与您的评论不符......