-2

编写了一些代码以通过二次公式查找多项式的根,但是在解析时它到达了文件的末尾。我所有的花括号都是闭合的,所以我不确定错误在哪里。有人能看出为什么吗?

        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;
            }
        }

}

编辑:最后缺少花括号,已修复。

4

2 回答 2

2

如果您的花括号没有完全结束,或者最后可能有额外的括号,则可能会发生这种情况。因此,请检查每个函数和类的左括号和右括号。这可能会解决您的问题。我之前经历过这个编译器错误,并且上述解决方案每次都有效。

于 2015-08-28T15:24:03.697 回答
1

最后我缺少花括号,已修复

于 2018-04-27T20:00:09.127 回答