Explanation
1. The self-increment () self-decrement (-) operator is a special arithmetic operator. It requires two operands to operate, and the self-increment The self-reduce operator is one operand.
2. Prefix auto-increment and auto-decrement method (a, -a): perform self-increment or self-decrement operation, and then perform expression operation.
3. Suffix auto-increment and self-decrement method (a, a-): perform expression operation first, and then perform auto-increment or self-decrement operation.
Example
public static void main(String[] args) { int a = 5;//定义一个变量; int b = 5; int x = 2 * ++a; int y = 2 * b++; //自增运算符前缀运算后a=6,x=12 System.out.println("自增运算符前缀运算后a=" + a + ",x=" + x); //自增运算符后缀运算后b=6,y=10 System.out.println("自增运算符后缀运算后b=" + b + ",y=" + y); }
1.As a representative of static object-oriented programming language, Java language realizes object-oriented theory, Allows programmers to perform complex programming with elegant thinking.
2.Java has the characteristics of simplicity, object-oriented, distributed, security, platform independence and portability, and dynamic nature.
3. Use Java to write desktop applications, Web applications, distributed systems and embedded system applications, etc.
The above is the detailed content of How to use increment and decrement operators in Java. For more information, please follow other related articles on the PHP Chinese website!