As shown in the program, the result is: 8and2. I don’t want to understand how to calculate it. Isn’t +1 processing for each round of for loop? In addition, the red box is x+ and +y. What does the + sign mean before and after? Thank God for answering

Welcome Guest.

+1

VotesThis is the first two loops of your loop and self-added content

, because if ((++x>2)||(++y>2)) does not hold, so x, y each add 1

until x=2, y=2

In JAVA’s || judgment, as long as one condition is true, the latter condition will not be executed, so The third loop begins

Because ++x>2 is true, ++y is no longer executed until the end of the loop y=2

and x is added to each loop.

3rd cycle x=4 y=2

4th cycle x=6 y=2

5th cycle x=8 y=2

Final Results

8and2

As for

The difference between ++x and x++, one is first added, the other is post added, generally The textbook has a detailed introduction. For this program, there is no difference between the two.

Only

z=x++ and z=++x are different.

x=1,

z=x++; //Results z=1, x=2, first assign value, then add 1

z=++x; //Result z= 2,x=2, first add 1, then assign value

Susan Morris- April 18, 2019 |