在我的代码中找不到符号变量java error
我有下面的代码,它应该设置一个初始值为null的术语,然后通过for循环返回经过修改的术语。 然而,当我试图编译时,给出了一个错误,称为变量项找不到符号(在if语句/for循环末尾的第10行)。 我不明白为什么会出现这个错误,也不知道如何修复它。 任何帮助都将不胜感激
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;
}
# 1 楼答案
试试这个:
而不是
# 2 楼答案
从JLS 15.9. Class Instance Creation Expressions
因此,将其改为以下内容: