开始学习Java已经三天了。
我有这个程序,但我不明白其中的代码main
方法与++
and --
运营商。我什至不知道该怎么称呼他们(这些操作员的名字)
谁能给我解释一下这是怎么回事。
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
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.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)