++前置(如++a):当参与运算时,变量a的值先自增1,然后用自增后的新值再参与运算;
++后置(如a++):当参与运算时,变量a先使用原有值参与运算,变量a的值再自增1。
class Test_1
{
public static void main(String[] args)
{
int x = 3;
int y;
y = x++ +10;
System.out.println("x ="+x);
System.out.println("y ="+y);
}
}
运行结果为:x =4; y =13
class Test_2
{
public static void main(String[] args)
{
int x = 0;
int y = 0;
int[] arr = {1,3,5,7,8};
System.out.println(arr[x++]);
System.out.println(arr[++x]);
System.out.println(arr[++y]);
}
}
运行结果为:1 5 3