i++与++i
i++是先赋值,再自增1
++i是先自增1,再赋值
public class Demo2
{
public static void main(String[] args) {
int a=1;
int b=a++; //a先赋值给b,运行完此行后a+1为2
int c=++a;//a为2,运行此行时a+1为3赋值给c
System.out.println(b);//1
System.out.println(c);//3
System.out.println("----------------------");
int i=1;
int j=++i;
int k=i++;
System.out.println(j);//2 运行此行时,i先自增1为2赋给j
System.out.println(k);//2 i此时为2先赋给k,运行完此行后i自增1为3
System.out.println(i);//3
}