belongs to collection: Java Basic Solved Programs
Fibonacci series is in the form of 1, 1, 2, 3, 5, 8, 13, 21,……
To find this series we add two previous terms/digits and get next term/number.
SOURCE CODE :
import java.util.Scanner; public class Fibonacci { public static void main(String[] args) { int a=1,b=1,n,fibon=1; Scanner sc = new Scanner(System.in); System.out.println("Enter how many terms u want : "); n=sc.nextInt(); System.out.print(fibon); while(n>1) { System.out.print(" "+fibon); fibon=a+b; a=b; b=fibon; n--; } System.out.println(""); } }
OUTPUT ::
Enter how many terms u want : 11 1 1 2 3 5 8 13 21 34 55 89
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
SOURCE CODE :
OUTPUT ::
need an explanation for this answer? contact us directly to get an explanation for this answer