Java增量/减量运算符 - 它们的行为方式,功能是什么?

Ama*_*Ass 3 java oop operators

我开始学习Java已经3天了.我有这个程序,我不理解main方法++--运算符中的代码.我甚至不知道该怎么称呼它们(这些操作员的名字)任何人都可以解释我的全部内容.

class Example {
    public static void main(String[] args) {
         x=0;
         x++;
         System.out.println(x);
         y=1;
         y--;
         System.out.println(y);
         z=3;
         ++z;
         System.out.println(z);
     }
}
Run Code Online (Sandbox Code Playgroud)

Dha*_*uka 15

这些被称为前后增量/减量运算符.

x++;
Run Code Online (Sandbox Code Playgroud)

是相同的 x = x + 1;

x--;
Run Code Online (Sandbox Code Playgroud)

是相同的 x = x - 1;

将运算符放在变量之前++x;意味着,首先递增x1,然后使用此新值x

int x = 0; 
int z = ++x; // produce x is 1, z is 1


    int x = 0;
    int z = x++;  // produce x is 1, but z is 0 , 
                  //z gets the value of x and then x is incremented. 
Run Code Online (Sandbox Code Playgroud)