Unable to get expected output using Java code menu

User Tag List

Results 1 to 1 of 1
  1. #1
    sheen8's Avatar Banned
    Reputation
    1
    Join Date
    Mar 2023
    Posts
    8
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unable to get expected output using Java code

    I am having difficulty understanding why my code is not producing the expected output. I am using Java and am trying to solve a problem from here.

    The problem I am trying to solve is as follows:

    "Given a number n, find the nth Fibonacci number. The Fibonacci sequence is a series of numbers where the first two numbers are 0 and 1, and each subsequent number is the sum of the previous two numbers.

    For example:
    PHP Code:
    0
    F1 
    1
    F2 
    F0 F1 1
    F3 
    F1 F2 
    Given n = 4, the output should be 3.

    Here is the code I have written so far:
    PHP Code:
    public class Fibonacci {
      public static 
    int Fibonacci(int n) { 
        if (
    == 0) {
            return 
    0;
        } else if (
    == 1) {
            return 
    1;
        } else {
            return 
    Fibonacci(n-1) + Fibonacci(n-2);
        }
      }
     public static 
    void main (String[] args) { 
        
    int n 4
        
    System.out.println(Fibonacci(n)); 
      }


    However, when I run the code, I get the output 0 instead of 3. I have tried troubleshooting the code, but have not been able to find the issue. Could someone please help me figure out why the code is not producing the expected output?

    Thank you.

    Unable to get expected output using Java code

Similar Threads

  1. Making someone unable to get invited until they log
    By anton412 in forum World of Warcraft Exploits
    Replies: 22
    Last Post: 03-08-2009, 11:25 PM
  2. [Question] How to get server hosted using wamp
    By Flame_Warrior in forum WoW EMU Guides & Tutorials
    Replies: 4
    Last Post: 12-14-2008, 01:47 PM
  3. Unable to get to character select
    By Jezee in forum WoW EMU Questions & Requests
    Replies: 5
    Last Post: 08-29-2008, 11:29 PM
  4. Tip Not to get scammed while useing paypal/scam partial method
    By PBALLER325 in forum WoW Scam Prevention
    Replies: 2
    Last Post: 06-10-2008, 03:38 PM
  5. LUA - Unable to get mob to cast on Target
    By vb4evr in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 03-06-2008, 09:56 PM
All times are GMT -5. The time now is 10:52 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search