写了一些代码,通过二次公式找到多项式的根,但它在解析时到达文件的末尾。我所有的花括号都关闭了,所以我不确定错误在哪里。谁能明白为什么?
public static void main(String[] args){ //execute the previously defined methods to calculate the quadratic equation.
while (cont){
Scanner Ascanner = new Scanner(System.in); //Created a new scanner variable for the A value.
double a = Ascanner.nextInt(); //Storing the next integer of that scanner variable for an Integer of the A value.
double b = Ascanner.nextInt(); //Storing the next integer of that scanner variable for an Integer for the B value.
double c = Ascanner.nextInt(); //Storing the next integer of that scanner variable for an Integer of the C value.
//Finding the radicand
double tem1 = handleradicand(a,b,c);
System.out.println("radicand" + tem1);
//Finding the radical
if (tem1 <= 0) {
double tem2 = sub_0rootradicand(tem1);
System.out.println("radical" + tem2);
double tem3 = divideBby2a (b,a);
double tem4 = divideRADby2a (tem2, a);
double firstX = findroot1 (tem3, tem4);
double secondX = findroot2 (tem3, tem4);
System.out.println("Your roots are X = i " + firstX + " " + "and X = i " + secondX);
} else {
double tem2 = rootradicand(tem1);
System.out.println("radical" + tem2);
double tem3 = divideBby2a (b,a);
double tem4 = divideRADby2a (tem2, a);
double firstX = findroot1 (tem3, tem4);
double secondX = findroot2 (tem3, tem4);
}
system.out.println("Again? (y/n)");
resp = Ascanner.next();
if(resp.equalsIgnoreCase("n") || resp.equalsIgnoreCase("y")){
if(resp.equalsIgnoreCase("n")){
cont = false;
} else {
cont = true;
}
}
}
编辑:最后错过了花括号,修复了。
答案 0 :(得分:2)
如果您的卷曲括号没有结束completeley,或者最后可能会有额外的括号,则可能会发生这种情况。因此,请检查每个函数和类的开括号和右括号。这可能会解决您的问题。我之前遇到过这个编译器错误,并且上述解决方案每次都有效。
答案 1 :(得分:1)
我最后错过了花括号,修复了