Синтаксическая ошибка при использовании CoreMath "public double ..." - PullRequest
0 голосов
/ 28 июня 2018

Это ошибка, которую я получаю:

Несколько маркеров на этой линии - Синтаксическая ошибка на токене "double", {ожидается
- Синтаксическая ошибка, введите «Идентификатор интерфейса» для завершения InterfaceHeader
- Синтаксическая ошибка на токене "double", @ ожидается
- Синтаксическая ошибка, вставьте ")" для завершения SingleMemberAnnotation
- Синтаксическая ошибка на токене "double", неверная (
- Синтаксическая ошибка, введите "}" для завершения 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;
                }
            }

Должен ли я декларировать все выше и ниже в других местах?

1 Ответ

0 голосов
/ 28 июня 2018

у вас есть завершение после объявления вашего метода

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(...);

...