Expand|Select|Wrap|Line Numbers
- import TerminalIO.*;
- public class Fibonacci
- {
- public static void main(String args[])
- {
- int n, z, q, x, num;
- System.out.println("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.print(num + " ");
- if (x == 0)
- {
- z = 0;
- }
- else
- {
- z = q;
- q = num; //Passes num's value into q
- }
- }
- }
- }
EDIT: I am so dumb. It is .readInt().
Also, my logic is wrong.