java 标记“-”上的语法错误,无效的 AssignmentOperator
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10467471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Syntax error on token "-", invalid AssignmentOperator
提问by Riemke Shabadoo
for (int iI = 4; iI > 0; iI--)
faAmount[iI] - faAmount[iI - 1];
This is the code it's in. How can I fix this?
这是它所在的代码。我该如何解决这个问题?
回答by Luiggi Mendoza
Maybe you forgot the equal sign
也许你忘了等号
for (int iI = 4; iI > 0; iI--)
faAmount[iI] -= faAmount[iI - 1];
Or to assign the difference in a variable
或分配变量中的差异
double x = 0; //or another value
for (int iI = 4; iI > 0; iI--)
x = faAmount[iI] - faAmount[iI - 1];
回答by MByD
faAmount[iI] - faAmount[iI - 1]
is n expression that have a result, but you don't assign it to anything, this is invalid in Java.
faAmount[iI] - faAmount[iI - 1]
是有结果的 n 表达式,但你没有将它分配给任何东西,这在 Java 中是无效的。
回答by trutheality
The technical explanation is that faAmount[iI] - faAmount[iI - 1]
is an expression but isn't a statement. The JLS notes that
技术上的解释是,这faAmount[iI] - faAmount[iI - 1]
是一个表达式,而不是一个语句。JLS 指出
Unlike C and C++, the Java programming language allows only certain forms of expressions to be used as expression statements.
与 C 和 C++ 不同,Java 编程语言只允许将某些形式的表达式用作表达式语句。
An additive expression is not one of those expressions that are also statements.
加法表达式不是那些也是语句的表达式之一。