Important thoughts on i++ and ++i
First look at the following program:
public class PPTest {
public static void main(String[] args) {
int x=0;
System.out.println("函数外x为:"+x);
test(x++);
System.out.println("现在x是:"+x);
test(++x);
System.out.println("现在x是:"+x);
}
public static void test(int x) {
System.out.println("函数内x为:"+x);
}
}
See the problem?
Yes, in the function, the parameter is called ++
, then the external data will also change
And, if it is 后++
, then the internal function calls the ++
previous value!
Such problems will have a significant impact when writing backtracking related problems! ! ! !
If you want to add to the function, it must be written i+1
in the form
public class PPTest {
public static void main(String[] args) {
int x=0;
System.out.println("函数外x为:"+x);
test(x+1);
System.out.println("现在x是:"+x);
}
public static void test(int x) {
System.out.println("函数内x为:"+x);
}
}
md, I did not expect to be ++
troubled by the problem at this time