write a java program that print the Fibonacci series for a give number

Java program to print Fibonacci series example

In this program, we will learn to print Fibonacci series numbers in java with source code

Source Code: Fibonacci series in java

import java.io.*; 
class Fibonacci {
public static void main(String[] args) throws IOException
{
DataInputStream in=new DataInputStream(System.in);
String s;
int a=1,b=1,c=a+b;
int n;
System.out.print("Enter nth value? ");
s=in.readLine();
n=Integer.parseInt(s);
System.out.print(a+","+b);
while(c<=n)
{
// fibonacci series formula | fibonacci series logic
System.out.print(c+",");
a=b;
b=c;
c=a+b;
}
}
}

Output: Fibonacci series list

Compilation & Execution: D:/cse>javac fibonacci.java
D:/cse>java fibanocci
 
Enter nth value? 21

1,1,2,3,5,8,13,21

Recommended Post:

Find the solution to the salesforce Question and many more

Tags: fibonacci series in java,fibonacci series java,fibonacci series formula,fibonacci series code,fibonacci series logic,fibonacci series numbers,fibonacci series example,fibonacci series list,fibonacci series equation,fibonacci series logic in java

Pramod Kumar Yadav is from Janakpur Dham, Nepal. He was born on December 23, 1994, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.



3 thoughts on “write a java program that print the Fibonacci series for a give number”

Leave a Comment