#I need help understanding this code

6 messages · Page 1 of 1 (latest)

jolly python
#

// on line number 4 (int rem = n%10;). After getting the remainder of every time loop runs. Does the n variable will keep getting changed. If so why. As per knowledge in java if you make any changes inside the specific block. It should not affect anything that are present outside of block. Please correct me if I am wrong, sorry if you could not understand my question here. I tried to explain as detail as I can. Thank you

    ''' //  print the input in reverse order?

    int n= 135363;
    int ans = 0;

    while(n>0) { 
        int rem = n % 10; 
         n /=10;         

     ans = ans * 10 + rem; 
    }
    System.out.println(ans); '''
river veldtBOT
#

This post has been reserved for your question.

Hey @jolly python! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

pearl leaf
#

The n variable is not limited to the block of the while loop. any changes made to 'n' inside the loop will affect the value of 'n' outside of the loop.

jolly python
#

Thank you for the answer

river veldtBOT
# jolly python Thank you for the answer

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.