[go: up one dir, main page]

0% found this document useful (0 votes)
2 views2 pages

Fibonacci Series Program

The document describes a Java program that generates the Fibonacci series, starting with the numbers 0 and 1. It uses a loop to calculate and print the next Fibonacci numbers until a total of 10 numbers are displayed. The variables used in the program are detailed, along with the algorithm steps for generating the series.

Uploaded by

commercezonebpl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Fibonacci Series Program

The document describes a Java program that generates the Fibonacci series, starting with the numbers 0 and 1. It uses a loop to calculate and print the next Fibonacci numbers until a total of 10 numbers are displayed. The variables used in the program are detailed, along with the algorithm steps for generating the series.

Uploaded by

commercezonebpl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Fibonacci Series Program

Code
public class Number {
void fibonacci() {
int f = 0, s = 1, t;
System.out.println(f);
System.out.println(s);
int n = 2;
while (n < 10) {
t = f + s;
System.out.println(t);
f = s;
s = t;
n++;
}
}
}

Variable Description
Variable Name Data Type Description

f int First number in the


Fibonacci series (initially 0)

s int Second number in the


Fibonacci series (initially 1)

t int Stores the next number in


the Fibonacci series (sum of
previous two)

n int Counter to track how many


Fibonacci numbers have
been printed

Algorithm
1. Start.
2. Initialize first two Fibonacci numbers f = 0 and s = 1.
3. Print f and s.
4. Initialize counter n = 2 (since first two numbers are printed).
5. While n < 10 (to print a total of 10 Fibonacci numbers):
6. - Calculate t = f + s.
7. - Print t.
8. - Update f = s and s = t.
9. - Increment n by 1.
10. Stop.

You might also like