Consider a sequence of the form 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149…
Write a method Met which takes as parameter an integer n and prints the nth term of the above sequence. The nth term will fit in an integer value.
Hint: Does this pattern look familiar? Remember the logic for Fibonacci series? can u help me in the java
Answers
Answered by
1
Answer:
import java.util.Scanner ;
public class Fibonacci
{
public static void main(String[] args)
{
int n, a = 0, b = 0, c = 1 ;
Scanner s = new Scanner(System.in) ; System.out.print("Enter value of n:") ;
n = s.nextInt() ;
System.out.print("Fibonacci Series:") ;
for(int i = 1; i <= n; i++)
{
a = b;
b = c;
c = a + b;
System.out.print(a+" ");
}
}
}
Similar questions