【发布时间】:2016-10-12 08:38:18
【问题描述】:
谁能解释我为什么会得到
error: unexpected type
System.out.println("PostFixOperators for b with addition of a "+b++ +=a);
required: variable
found: value
在编译时运行此代码。
public class PostFixOperators {
static int a, b ;
public static void main(String arv[]) {
System.out.println("PostFixOperators for a "+ a++);
System.out.println("PostFixOpearators for b with addition of a "+b++ +=a);
}
}
【问题讨论】:
-
这不是有效的 Java 语法。你这样发表声明的目的是什么?不清楚你为什么要写类似
"..."+b++ +=a -
您不能在
b++上调用+=a,因为b++不是变量——它是b在b递增之前的旧值。 -
将
a++的值存储在变量a中并对b 执行相同操作,然后将其打印出来。