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 8637019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:22:17+00:00 2026-06-12T10:22:17+00:00

What is the code to write in int Fibonacci (int n) without using if

  • 0

What is the code to write in int Fibonacci (int n) without using “if” like they did here Java recursive Fibonacci sequence ?
I tried to write this but it is wrong :
Because in this program the list will be 1 1 2 3 5 8 and not 0 1 1 2 3 5 8

Here is the program I tried to write:

public class Fibonacci
{
    public static void main(String[] args)
    {
        int f = 0;
        int g = 1;

        for(int i = 1; i <= 10; i++)
        {
            f = f + g;
            g = f - g;
            System.out.print(f + " ");
        }

        System.out.println();
    }
}
  • 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-12T10:22:19+00:00Added an answer on June 12, 2026 at 10:22 am

    Your program is entirely correct; all you need to change is the location of the print statement:

    public static void main(String[] args) {
      int f = 0;
      int g = 1;
    
      for(int i = 1; i <= 10; i++)
      {
        System.out.print(f + " ");
        f = f + g;
        g = f - g;
      } 
    
      System.out.println();
    }
    

    Alternatively, print g instead of f.

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

Sidebar

Related Questions

I'm trying to write a video using opencv's VideoWriter. Here's code: int main() {
Using the following code to write to a file int main(int argc, char *
I occasionally write code something like this: // file1.cpp #define DO_THIS 1 #if DO_THIS
WebGL is shader based. In my shaders I can write code like int a
firstly, i write this code: int X, Y; for (i=0; i<N; i++) { printf(Enter
I want to be able to write code like this: HWND hwnd = <the
Where can we write code like struct Foo { int bar; int baz; }
Here is the code: class Fibonacci { static final int MIN_INDEX = 1; public
I have Nvidia geforce 310M and when i write this code int main() {
I got a code from here to write a Int array to file. However,

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.