variable description table for Fibonacci series
Answers
Answer:
The Fibonacci series is a series where the next term is the sum of pervious two terms. The first two terms of the Fibonacci sequence is 0 followed by 1.
The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, ...
Example 1: Display Fibonacci series using for loop
public class Fibonacci {
public static void main(String[] args) {
int n = 10, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");
for (int i = 1; i <= n; ++i)
{
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
}
}
}
Answer:
import java .util .scanner ;
public class Main{
public statuc void main(string[]args ){
scanner scan = new scanner (system.in);
system.out.println(enter number);
int number= scan.next Int():
int n1=0;
int n2=1;
system .out .println(n1);
system.out.println(n2);
for( int i=1;i<=number;i++){
int n3=n1 +n2;
system.out.println(n3);
n1 =n2;
n2= n3;
}
}
}
.
Explanation:
variable description
int n3 = to add the sum of n1 and n2 and make other number which will store in n3.
int n1= to print the number 1.
int n2 =to print the number 2.