【发布时间】:2023-02-16 23:06:32
【问题描述】:
public class Roots{
public static void main(String[] args) {
}
public void roots(int coefSquare, int coefX, int noCoef) {
int square1 = (int) (((coefX*(-1)) + Math.sqrt(coefX*coefX - 4*coefSquare*noCoef))/2*coefSquare);
int square2 = (int) (((coefX*(-1)) - Math.sqrt(coefX*coefX - 4*coefSquare*noCoef))/2*coefSquare);
roots(1 , 6 , 9);
System.out.println(square1);
System.out.println(square2);
}
}
我试图把这个功能从空白中剔除。它没有用。
【问题讨论】:
-
您没有调用该函数。
-
除了您不调用函数/方法之外,该方法还包含对自身的无条件调用
roots(1 , 6 , 9);这将导致该方法调用自身,直到发生堆栈溢出(如果曾经调用过)。您可能是想将该行放入您的主要方法中吗? -
欢迎来到堆栈溢出!这是您开始熟悉using a debugger 的好机会。当您在调试器中单步执行代码时,哪个操作首先会产生意外结果?该操作中使用的值是什么?结果如何?预期的结果是什么?为什么?要了解有关此社区的更多信息以及我们如何为您提供帮助,请从tour 开始并阅读How to Ask 及其链接资源。