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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:57:47+00:00 2026-06-13T11:57:47+00:00

Trying to write a simple program that prints the Fibonacci sequence. I want to

  • 0

Trying to write a simple program that prints the Fibonacci sequence. I want to create a method named fibNumber that calculates the value of the Fibonacci sequence and then I want to use a for loop in the run() method to print that value 15 times. The trouble I’m having is the println method in the for loop. Eclipse says “n cannot be resolved to a value” and “i cannot be resolved to a value.” I thought I covered all the bases in terms of declaring the variables. Am I missing something?

What I want to write is all the way up to F15

F0 = 0
F1 = 1

F2 = 1
F3 = 2
F4 = 3
F5 = 5

import acm.program.*;


public class FiccononicSequence extends ConsoleProgram {

public void run(){
    println("This program prints out the Fibonacci sequence.");

    for (i = 1; i <= 15; i++){

        println("F" + i + " = " + fibNumber(n));

    }




}


private int fibNumber(int n){
    if (n == 0){
    return 0; 
    }else{ if (n == 1){
    return 1;
    }else{
    return fibNumber(n - 1) + fibNumber(n - 2);




}      
  • 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-13T11:57:49+00:00Added an answer on June 13, 2026 at 11:57 am

    Try this…

    – The problem here is about the scope of the variable.

    – i should be declared of type int, which is local to the run() method instead of n, as n is another local variable in fibNumber() method.

    – i and n are totally in different scope and are invisible to each other.

    for (int i = 1; i <= 15; i++){
    
            println("F" + i + " = " + fibNumber(i));  // i should be here.
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a simple program that prints out a C string
I'm trying to write a simple java program in Eclipse that prints these four
I'm trying to write a simple program that prints the first Stirling's approximation for
I'm trying to write a simple program that takes in the users input, then
I am trying to write a simple program in C# that will read data
I'm trying to write a very simple program, I want to print out the
I'm trying to write a simple program that will receive a string of max
i am trying to run a very simple java program. i want to write
I'm trying to write a simple high-low program that will output like this: $
Hey guys I'm trying to write a simple socket program that basically send like

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.