#How come there are 32 5's being printed ?

1 messages · Page 1 of 1 (latest)

tired wasp
#
public class Sample17{
    static void meth17(int a){
        while(a<=4){         
           meth17(++a);
        }
        System.out.println(a);
    }
    public static void main(String[] args) {
        meth17(0);
        
    }
}
drowsy robinBOT
#

This post has been reserved for your question.

Hey @tired wasp! Please use /close or the Close Post button above when your problem is solved. 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.

true condor
#

32 is 2^5, you're basically calling the method 32 times recursively. Plus you print at the end, so when everything is done, a will be 5

tired wasp
#

after step 4 step 2 and 3 are repeated back and forth until the condition turns false and breaks out of while loop and from here I am assuming after breaking out of the while loop it should print the last value of a i.e 5 and exit the program

tired wasp
true condor
#

I made an assumption, did not run the code 🙂

drowsy robinBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

tired wasp
#
meth1meth2meth3meth4meth5 false prints

meth5 false prints
meth4meth5 false prints 
    meth5 false prints
meth3meth4meth5 false prints 
    meth5 false prints 
        meth4meth5 false prints 
            meth5 false prints 
    
meth2meth3meth4meth5 false prints 
    meth5 false prints
        meth4meth5 false prints 
            meth5 false prints 
    meth3meth4meth5 false prints
        meth5 false prints
                    meth4meth5 false prints 
                meth5 false prints

meth1meth2meth3meth4meth5 false prints
    meth5 false prints
    meth4meth5 false prints
        meth5 false prints
           meth3meth4meth5 false prints
        meth5 false prints
        meth4meth5 false prints
        meth5 false prints

  meth2meth3meth4meth5 false prints 
           meth5 false prints
        meth4meth5 false prints 
            meth5 false prints 
    meth3meth4meth5 false prints
        meth5 false prints
                    meth4meth5 false prints 
                meth5 false prints