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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:05:33+00:00 2026-05-29T04:05:33+00:00

I am looking for a clear explanation to my question (NOT looking for code),

  • 0

I am looking for a clear explanation to my question (NOT looking for code), but if a bit of code helps to explain yourself, then please do.. thank you 🙂

Question:

-using Java

-Main class asks user for an integer input (fibonacci N term), then proceeds to calculate all the fibonacci numbers, in order, until it reaches that term.

-everything is stored into a single arraylists, of type integer. (Each digit is broken up and stored in its own index, so it is its own “element”, so to speak.)

For example, i am aiming for it to go something like this:

“Please enter an N fibonacci term:”

10

At this point now, internally, I have stored the 2 base cases in an arraylist, that look like this:

ArrayList: [1, 1]

Now, I am trying to make my arraylist look like this, after user input:

[1, 1, 2, 3, 5, 8, 1, 3, 2, 1, 3, 4, 5, 5]

(notice how it stopped at the last term, 55, and also notice how the double digit values are broken up into separate elements.)

I have no problem breaking up the digits, its just the “calculating” that is giving me a hard time.. thanks in advance for any advice

  • 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-29T04:05:34+00:00Added an answer on May 29, 2026 at 4:05 am

    It sounds like you want to walk the Fibonacci sequence, starting with F1, while appending the digits as ints to an ArrayList<int> as you go. Since you want the digits in base-10, I think this would be easiest to read if you convert the intermediate Fibonacci integers to strings, then step through each char in the string as a character array. As you step through it, you can convert each digit back to an integer by subtracting the char ‘0’ from it. You can then append the numerical version of that digit to the ArrayList<int>. The end result would look like something like this:

    ArrayList<int> arrayList = new ArrayList<int>();
    
    int a = 1;
    int b = 0;
    int n = 1;
    
    while (n++ <= input) {  // input being from the user
        a += b;
        b = a - b;
    
        char[] fib = Integer.toString(b).toCharArray();
        for (int i = 0; i < fib.length; i++) {
            arrayList.add(fib[i] - '0');
        }
    }
    

    The takeaway here is that you don’t mess around with your numerical values as you’re walking up the Fibonacci sequence. Instead, you cache off a copy of ‘b’ that you transform into a string before determining the value of each digit that will go into the ArrayList<int>.

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

Sidebar

Related Questions

I am looking for a clear explanation to my question (NOT looking for code),
I am looking for a clear explanation to my question (NOT looking for code),
I've been looking on the Internet for a fairly clear explanation of the different
May be my title is not clear. I am looking for some kind of
I am using VS 2008. Looking around on the forums/stack hasn't provided a clear
I am looking to find a clear explanation of what the "this" keyword does,
I am looking for a clear explanation of what the MERGE statement in Oracle
I've been looking around for some time and couldn't find a clear explanation for
I'm looking for a clear, concise and accurate answer. Ideally as the actual answer,
I am looking for a clear definition of what a tokenizer, parser and lexer

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.