fibonacci series

Fibonacci series is a series of numbers in which each number is the sum of the two preceding numbers.  For example 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987 ..more

Write a program to print the Fibonacci series. Accept a number from the user and print the Fibonacci series up to that number.

For other basic java program click the given link.
https://java4school.com/solved-programs-class-9-beginner

// series of numbers in which each number is the sum of the two preceding //numbers.0,1, 1, 2, 3, 5, 8..... 
import java.io.*; 
class fibonacci 
{ 
public static void main()throws IOException 
{ 
BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
System.out.println("Enter a number of your choice"); 
int n=Integer.parseInt(br.readLine()); 
int a=0,b=1; 
int sum=0; 
System.out.print(a+","); 
System.out.print(b+","); 
while(sum<=n) 
{ 
Output:=a+b; 
System.out.println(sum+","); 
a=b; 
b=sum; 
} 
} 
} 

Output:Enter a number of your choice
5
0,1,1,2,3,5

To learn how to install Bluej watch the video https://youtu.be/i845Tz5_QXU

LEAVE A REPLY

Please enter your comment!
Please enter your name here