Fibonacci Sequence
A java notebook saying with Fibonacci Sequence.
class Fibo {
public static void main(String[] args) {
Scanner input;
input = new Scanner(System.in);
System.out.print("Type in amount of numbers for sequence --> ");
try {
int N = input.nextInt();
int x1 = 0, x2 = 1;
int count = 0;
while (count < N) {
System.out.print(x1 + " ");
int x3 = x2 + x1;
x1 = x2;
x2 = x3;
count = count + 1;
}
} catch (Exception e) {
System.out.println("Input must be an integer " + e);
}
}
}
Fibo.main(null)