bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java How To's
Java•Java How To's

Java How To - Fibonacci Sequence

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java How To - Fibonacci Sequence?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ n1 = 0, n2 = 1, count = 10;

How To Generate Fibonacci Sequence

Print the first 10 numbers of the Fibonacci sequence:

Example

int n1 = 0, n2 = 1, count = 10;
System.out.print("Fibonacci: " + n1 + " " + n2);
for (int i = 2; i < count; i++) {
  int n3 = n1 + n2;
  System.out.print(" " + n3);
  n1 = n2;
  n2 = n3;
}
// Output: Fibonacci: 0 1 1 2 3 5 8 13 21 34

Previous

Java How To - Calculate Factorial of a Number

Next

Java How To Find the GCD