**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

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

**Recommended Post:**

- Java roll dice 10000 times with algorithm and source code
- Write a Java program that displays the number of characters, lines, and words in a text
- Write a Java program that reads a file and displays the file on the screen with a line number before each line
- Write a Java program that reads a file name from the user, then displays information about whether the file exists, readable, writable, type of file, and the length of the file in bytes
- Java program to make frequency count of vowels, consonants, special symbols, digits, words in a given text
- Write a Java program for sorting a given list of names in ascending order
- Write a java program to Checks whether a given string is a palindrome or not
- Write a java program to perform multiplication of two matrices
- write a java program that prints the Fibonacci series for a given number.

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

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