[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.
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.
Comment