1

i have the following code that is supposed to set up a Term with an initial value of null, and then return the term as altered through the for loop. However when i try to compile gives an error saying cannot find symbol for variable Term (on line 10 at the end of the if statement/for loop). i don't understand why I am getting this error or how to fix it. Any help would be much appreciated.

 public Term nextTerm()
   {
   double coefficient = 0.0;
   int exp = 0;
   Term term = new Term(coefficient,exp);
        for (exp = 0; exp < sequence.length ; exp++){
       double[] diffArray = differences();
       if (allEqual() == false) {
           coefficient = diffArray[0]/factorial(exp);
           term = Term(coefficient, exp);
        }
    }
   return term;
}

3 Answers 3

1

Here:

term = Term(coefficient, exp);

You get a compilation error because Term(var1, var2) is not a valid method available in the class. It should be:

term = new Term(coefficient, exp);
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

term = new Term(coefficient, exp);

instead of

term = Term(coefficient, exp);

Comments

0

From JLS 15.9. Class Instance Creation Expressions

A class instance creation expression is used to create new objects that are instances of classes.

  • UnqualifiedClassInstanceCreationExpression: new [TypeArguments] ClassOrInterfaceTypeToInstantiate ( [ArgumentList] )[ClassBody]

So change it to following:

term = new Term(coefficient, exp);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.