Question 4)
Write a Program to find the Fibonacci series.
Answer:-
import java.util.Scanner;
public class FSeries {
public static void main(String[] args) {
Scanner ss = new Scanner(System.in);
System.out.println("Enter any number :");
int number = ss.nextInt();
int a=0, b=1;
System.out.println("The Feboncci series of 0 to " +number +"th terms is : ");
for (int i=0; i<=number; i++) {
System.out.print(a + " ");
int next = a + b;
a = b;
b = next;
}
}
}
0 Comments