using java write a menu driven programme to print the following swicth case statement 1 first ten terms of fabonnoci series :1,1,2,3,8........ [it starts from 1,1 and the subsequent nos ]. 2 first fiftten nos of Lucas series 2,1,3,4,7,11,18....... [it starts from 2and1,and the subsiquent numbers and the sum of the previous to numbers . 3 first ten number of Pell series : Pell series is such a series which strats from 1 and 2 and the subsequent nos are sum of twice the previous number annd no previous to the nos
Answers
Answered by
3
Answer:
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;
}
}
}
Fibonacci series using while loop
public class Fibonacci {
public static void main(String[] args) {
int i = 1, n = 10, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");
while (i <= n)
{
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
i++;
}
}
}
Similar questions