从下面或这里的程序,为什么最后一次调用System.out.println(i)打印值7?
class PrePostDemo {
public static void main(String[] args){
int i = 3;
i++;
System.out.println(i); // "4"
++i;
System.out.println(i); // "5"
System.out.println(++i); // "6"
System.out.println(i++); // "6"
System.out.println(i); // "7"
}
}
Run Code Online (Sandbox Code Playgroud) 我对增量和减量运算符有疑问.我无法理解为什么java会给出这些输出.
x = 5; y = 10;
System.out.println(z = y *= x++); // output is 50
x = 2; y = 3; z = 4;
System.out.println("Result = "+ z + y++ * x); // output is Result = 46
x = 5;
System.out.println( x++*x); // output is 30
x = 5;
System.out.println( x*x++); // output is 25
Run Code Online (Sandbox Code Playgroud)
例如,在第二个println函数中,y在不增加1的情况下被乘法,在第三个函数中,x与x + 1相乘.因为我知道一元递增和一元递减运算符比算术运算符具有更高的优先级所以为什么第二个算术计算而不增加1(y ++*x = 3*2 = 6那里为什么不(y + 1)*x = 8?