The i operator in Java increases the value of variable i by 1. The specific operation is: take the current value of i. Increase the value of i by 1. Returns the modified value of i. i can be used as either a prefix or a suffix. If it is a prefix, it will take the value after it is incremented. If it is a suffix, it will take its value first and then it will increase itself.
i in Java: increment operator
i in Java
is An increment operator, its function is to increase the value of variable i
by 1.
Specifically, when the i
operator is applied to a variable, it does the following:
It should be noted that the i
operator has two usages: prefix usage and suffix usage.
Prefix usage: i
In prefix usage, the
operator appears in front of the variable. In this case, the value of the variable is incremented by 1 before being used. For example:
<code class="java">int i = 5; ++i; // i 的值变为 6</code>
Suffix usage: i
In suffix usage, the
operator appears after the variable. In this case, the value of the variable is incremented by 1 after use. For example:
<code class="java">int i = 5; int j = i++; // i 的值变为 6,j 的值变为 5</code>
It is worth noting that in suffix usage, the value of the variable is modified after the operator is executed, so in the expression, the value of the variable remains unchanged.
The above is the detailed content of What does i++ in java mean?. For more information, please follow other related articles on the PHP Chinese website!