Write a program in Java to print the following series.
0, 1, 1, 2, 3, 5, 8 ……. Upto n terms.
Answers
Answered by
9
Answer:
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;
}
}
}
Answered by
0
Answer:public class Learning
{
public static void main(String[] args) {
int n1=0;
int n2=1;
int s;
int n=20;
System.out.println(n1);
System.out.println(n2);
for (int i=1;i<n;i++)
{
s=n1+n2;
n1=n2;
n2=s;
System.out.println(s);
}
}
}
Explanation:
Similar questions