csci001
csci001

Reputation: 33

cannot find symbol variable java error in my code

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

Upvotes: 1

Views: 418

Answers (3)

Sumit Singh
Sumit Singh

Reputation: 15896

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

Upvotes: 0

Rahul Tripathi
Rahul Tripathi

Reputation: 172448

Try this:

term = new Term(coefficient, exp);

instead of

term = Term(coefficient, exp);

Upvotes: 0

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85779

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

Upvotes: 1

Related Questions