本文介绍了Java增量/减量运算符 - 它们的行为方式,功能是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始学习Java已经3天了。
我有这个程序,我不懂主
方法中的代码 ++
和 -
运营商。我甚至不知道该怎么称呼它们(这些运营商的名字)
任何人都可以解释我的全部内容。
It's been 3 days since I start to learn Java.I have this program and I don't understand code in main
method with ++
and --
operators. I don't even know what to call them(name of these operators)Can anyone explain me what's all about.
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);
}
}
推荐答案
这些被称为前后增量/减量运算符。
x++;
与 x = x + 1;
x--;
与
x = x - 1;
将运算符放在变量
++ x;
之前表示,首先递增 x
按1,然后使用 x的新值
Putting the operator before the variable
++x;
means, first increment x
by 1, and then use this new value of 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.
这篇关于Java增量/减量运算符 - 它们的行为方式,功能是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!