从另一类的方法中调用变异器

问题描述 投票:0回答:1

我试图了解我在这里做错了什么

import java.lang.Math

public class QuadraticEquation {
        public static Roots findRoots(double a, double b, double c) {
            double d = b*b-4*a*c;
            double x1 = (-b + Math.sqrt(d))/2*a;
            double x2 = (-b - Math.sqrt(d))/2*a;
            Roots( x1, x2);

        }

        public static void main(String[] args) {
            Roots roots = QuadraticEquation.findRoots(2, 10, 8);
            System.out.println("Roots: " + roots.x1 + ", " + roots.x2);
        }
    }

    class Roots {
        public final double x1, x2;

        public Roots(double x1, double x2) {         
            this.x1 = x1;
            this.x2 = x2;
        }
    }

显然,它在public static Roots findRoots的最后一行上给了我一个错误:找不到符号,但我不知道还有什么其他方法可以调用变异器

java inner-classes mutators
1个回答
1
投票
Roots(x1, x2);
© www.soinside.com 2019 - 2024. All rights reserved.