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

  • SEARCH
  • Home
  • 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 8230337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:05:59+00:00 2026-06-07T17:05:59+00:00

Given this method call: public class MainClass { public static void main(String[] args) {

  • 0

Given this method call:

public class MainClass {

public static void main(String[] args) {
    System.out.println(fib(3));
}

private static int fib(int i) {
     System.out.println("Into fib with i = " + i);

    if (i < 2) {
        System.out.println("We got here");
        return i;
    }
    return fib(i-1) + fib(i-2); 
}

 }

I expected:

* fib(i-1) to return 2
* fib(i-2) to return 1
* return 2 + 1 to return 3

Result:

2

This is the output of console:

Into fib with i = 3
Into fib with i = 2
Into fib with i = 1
We got here
Into fib with i = 0
We got here

I understand everything up to this part:

Into fib with i = 0

When could have i ever been 0?

  • 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-06-07T17:06:00+00:00Added an answer on June 7, 2026 at 5:06 pm

    fib(3) calls fib(2). When you call fib(2), it will call fib(i-1) and fib(i-2), that is, fib(1) and fib(0).

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

Sidebar

Related Questions

Given the following method: public static void SetPropertyValue(object target, string propName, object value) {
I have following class with one static method: public class Helper { public static
In PHP 5.3.6 I have a class with a method like this: public function
Given this Java code: class Account { private Integer number = 0; public synchronized
I've come across a strange problem with method specialisation. Given this code... #include <string>
Given this class: class Tacobell{ public function order_taco(){ echo 3 Tacos, thank you.; }
Given a Runnable object e.g. public class Test implements Runnable { @Override public void
Given this method to work on a HTML page in a webbrowser: bool semaphoreForDocCompletedEvent;
UPDATE:: OK i am putting the original problem statement here Given the Main class
Given the following Class and Service layer signatures: public class PersonActionRequest { PersonVO person

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.