Quick question involving logic (RESOLVED)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MttTess
    New Member
    • Feb 2008
    • 1

    Quick question involving logic (RESOLVED)

    [CODE=Java]import TerminalIO.*;
    public class Fibonacci
    {
    public static void main(String args[])
    {
    int n, z, q, x, num;
    System.out.prin tln("Please enter the number of times you want the sequence to occur.");
    KeyboardReader input = new KeyboardReader( );
    n = input.readInt() ;
    num = 1;
    z = 0; //Stores the first number
    q = 1; //Stores the second number
    for (x = 0; x <= (n - 1); x = x + 1)
    {
    num = (z + q); //Sums the two numbers
    System.out.prin t(num + " ");
    if (x == 0)
    {
    z = 0;
    }
    else
    {
    z = q;
    q = num; //Passes num's value into q
    }
    }
    }

    }[/CODE]

    I am currently a junior in high school and was given this assignment for extracredit. I have to create a program that allows the user to enter a certain integer and based off of the input the Fibonacci Sequence (1,1,2,3,5,8,12 ) is executed that many times. I think I have the logic correct, but it appears that it is not liking the TerminalIO. Any help? =)

    EDIT: I am so dumb. It is .readInt().

    Also, my logic is wrong.
    Last edited by BigDaddyLH; Feb 14 '08, 11:05 PM. Reason: added code tags
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    Working...