Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6670855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:19:06+00:00 2026-05-26T03:19:06+00:00

why do i get this output ? I expect the output to be 10,9,8…

  • 0

why do i get this output ? I expect the output to be 10,9,8…

But it is 11,12,13….

class tester {

    static int i = 0;

    public static void main(String args[]) {
        recursive();
        System.out.println("after recursive");
    }

    public static void recursive() {
        while(i++<10) {
            recursive();
            System.out.println(i);
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:19:06+00:00Added an answer on May 26, 2026 at 3:19 am

    The simple logic is as follows:

    Since your incremental is a posfix increment, the original value is evaluated first, before increment.

    Logic:

    while (i++ < 10) { recursive();}
    
    1. i is initially 0, so, 0 < 10 (true), increment by 1. Now, call recursive().

    This loops (1) until i = 10. When i = 10 is evaluated, the while expression is false, so it leaves the loop.

    Remember, we have already called recursive() 10 times already, so it now needs to print i, 10 times, (since the JVM pushed recursive() function 10 times in the stack). Each times it pops the function, it goes back to the System.out.println(i) statement, knowing that i was incremented in each call, hence why you see values:

    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    after recursive
    

    That’s basically recursion in a nutshell. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class A { public void talk(){ this.sayIt(); } private void sayIt(){ System.out.println(class A says...);
From the following code, I expect to get this output from the corresponding input:
I would expect there to be three lines of output from this code, but
any idea how i can get the code below to produce this output? 1
In my output, I get @{ActiveSyncEnabled=False} how do I parse this so that it
How can you get 1 as an output from #2? #1 I ran this
I'm using toLocalizedTime to output a date, as below <span tal:content=python:here.toLocalisedTime(date.get('start_date'))/> This outputs eg.
In this slice of code I get an output of bbb 55 66 77
I've got this piece of code: using Posix; int fuseguifs_getattr(string path, Posix.Stat *stbuf) {
I tried different ways and also looked around but can't get this running. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.