OUTPUT 2011

The following is a part of some class. What will be the output of the function mymethod() when the value of the counter is equal to 3? Show the dry run/working

void mymethod(int counter)
    {
        if(counter==0)
            System.out.println("  ");
        else
        {
            System.out.println("Hello" +counter);
            mymethod(--counter);
            System.out.println(" "+counter);
        }
    }

mymethod(3)         Hello3

mymethod(2)         Hello2

mymethod(1)        Hello1

mymethod(0) 

                                0

                                 1

                                2

This entry was posted in Output. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *