Welcome Guest.


Java arithmetic operation

Asked by: Joseph 276 views IT April 18, 2019

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

1 Answers

  1. +1Votes  

    This 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


    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.


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


    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

    Question: Thank you for your answer. I have seen this in the book since the addition of the front and back. This is basically understandable, but the output is Where, x+ and +y represent what is included here Righteousness?

    Answer: This + is the string concatenation operation
    JAVA can automatically convert the int into a string and then stitch it into a string.
    x, y is int, and “and” is a string (string)
    Is to convert x, y into a String and then stitch it into a string

    Susan Morris- April 18, 2019 |