解析时到达文件末尾 (Java)
Reached end of file while parsing (Java)
写了一些代码通过二次公式求多项式的根,但在解析时它到达了文件末尾。我所有的花括号都关闭了,所以我不确定错误在哪里。有人能看出原因吗?
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;
}
}
}
编辑:最后缺少大括号,已修复。
如果您的花括号没有完全结束或者末尾可能有额外的括号,则可能会发生这种情况。因此,请检查每个函数的左括号和右括号以及 class。这可能会解决您的问题。我以前遇到过这个编译器错误,上面的解决方案每次都有效。
我最后缺少花括号,已修复
写了一些代码通过二次公式求多项式的根,但在解析时它到达了文件末尾。我所有的花括号都关闭了,所以我不确定错误在哪里。有人能看出原因吗?
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;
}
}
}
编辑:最后缺少大括号,已修复。
如果您的花括号没有完全结束或者末尾可能有额外的括号,则可能会发生这种情况。因此,请检查每个函数的左括号和右括号以及 class。这可能会解决您的问题。我以前遇到过这个编译器错误,上面的解决方案每次都有效。
我最后缺少花括号,已修复