01_javaSE face questions: Variable increment

Open brush face questions, questions are carried out in accordance with the video brushed

Increment variable, just remember two things

  • i ++ is calculated after the first assignment
  • ++ i is calculated after the first assignment

Look at the following code

        int i = 1;
        i = i++;
        int j = i++;
        int k = i + ++i * i++;
        System.out.println("i="+ i);
        System.out.println("j=" +j);
        System.out.println("k="+ k);

Here we must note two points

  1. Increment variable algorithm
  2. Operator precedence

Results are as follows

i=4
j=1
k=11

I'm just afraid of the same, and that is good enough for my suffering!

Guess you like

Origin www.cnblogs.com/zhenghengbin/p/11145043.html