In the basics of learning java, novices like me may be confused by i++ and ++i. I don’t know the difference between them. Here are examples to help you understand~
public class Demo04 {
public static void main(String[] args) {
int a = 1;
int b = a++; //先赋值给b再自增
int c = ++a; //先自增再赋值给c
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println("============================");
int i = 5;
int m = i--; //先赋值给m再自减
int n = --i; //先自减再赋值给n
System.out.println(i);
System.out.println(m);
System.out.println(n);
}
}
The output result is