Java 使用CoreMath“public double…”时出现语法错误

Java 使用CoreMath“public double…”时出现语法错误,java,bisection,Java,Bisection,这是我收到的错误: 这条线上有多个标记 -双令牌上的语法错误,{应为 -语法错误,请插入要完成的接口标识符 接口负责人 -令牌双精度上的语法错误,应为@ -语法错误,请插入以完成 单成员注释 -双令牌上的语法错误,无效 -语法错误,请插入}以完成 MemberValueArrayInitializer 这是我的代码: package CoreMath; public double evaluateRoot(double lower, doubl

这是我收到的错误:

这条线上有多个标记 -双令牌上的语法错误,{应为 -语法错误,请插入要完成的接口标识符 接口负责人 -令牌双精度上的语法错误,应为@ -语法错误,请插入以完成 单成员注释 -双令牌上的语法错误,无效 -语法错误,请插入}以完成 MemberValueArrayInitializer

这是我的代码:

            package CoreMath;


            public double evaluateRoot(double lower, double higher);
            //lower and higher are the initial estimates//
            {
                double fa; //fa and fb are the initial ‘guess’ values.//
                double fb;
                double fc; //fc is the function evaluation , fx//
                double midvalue=0;
                double precvalue=0; {
                    fa=computeFunction(lower); //ComputeFunction is implemented by the caller
                    fb=computeFunction(higher);
                    //Check to see if we have the root within the range bounds//
                    if (fa*fb>0)
                    { //If fa∗fb>0 then both are either positive or negative and don’t bracket zero.//

                        midvalue=0;//Terminate program//
                    }
                    else
                        do
                        {
                            precvalue=midvalue;//preceding value for testing relative precision//

                            midvalue = lower+0.5*(higher-lower);
                            fc=computeFunction(midvalue); //Computes the fx for the mid value//

                            // 1.2. Core Math’s Classes 5

                            if(fa*fc<0)
                            {
                                higher=midvalue;
                            }
                            else
                                if(fa*fc>0)
                                {
                                    lower=midvalue;
                                }

                        } while((abs(fc)>precisionvalue&i<iterations));//loops until desired number of iterations or precision is reached//

                    return midvalue;
                }
            }

我应该在其他地方声明更高和更低吗?

在方法声明之后,您有一个终止

public double evaluateRoot(double lower, double higher);
换成这个

public double evaluateRoot(double lower, double higher)
解决方案

public class A {

    // lower and higher are the initial estimates//
    public static double evaluateRoot(double lower, double higher) {
        double fa; // fa and fb are the initial ‘guess’ values.//
        double fb;
        double fc; // fc is the function evaluation , fx//
        double midvalue = 0;
        double precvalue = 0;
        {
            fa = computeFunction(lower); // ComputeFunction is implemented by the caller
            fb = computeFunction(higher);
            // Check to see if we have the root within the range bounds
            if (fa * fb > 0) { // If fa∗fb>0 then both are either positive or negative and don’t bracket zero.
                midvalue = 0;// Terminate program
            } else {
                do {
                    precvalue = midvalue;// preceding value for testing relative precision

                    midvalue = lower + 0.5 * (higher - lower);
                    fc = computeFunction(midvalue); // Computes the fx for the mid value

                    // 1.2. Core Math’s Classes 5

                    if (fa * fc < 0) {
                        higher = midvalue;
                    } else if (fa * fc > 0) {
                        lower = midvalue;
                    }

                }
                while ((abs(fc) > precisionvalue & i < iterations));// loops until desired number of iterations or precision is reached
            }

            return midvalue;
        }
    }
}

并称之为A.evaluateRoot

你的方法不在类中,或者你的包语句放错了地方。它是真正完整的代码还是你删掉了什么?类声明在哪里?删除public double evaluater后面的分号double lower,double higher;请把整个班级都贴上。如果这是完整的代码,您应该在类定义的前面开始几个步骤。我强烈建议您使用IDE来编写代码。语法错误通常是初学者的错误,这没问题,这里就是这样。但是,通过使用IDE学习编码,可以很容易地避免这种情况。例如,IDE可能会告诉您,您的代码在类之外,或者方法声明末尾的分号有问题,等等……这不是唯一的问题