- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to print the fibonacci series of a given number using while loop
Fibonacci Series generates subsequent number by adding two previous numbers. Fibonacci series starts from two numbers − F0 & F1. The initial values of F0 & F1 can be taken 0, 1 or 1, 1 respectively.
Example
public class FibonacciSeriesWithWhileLoop{ public static void main(String args[]) { int a, b, c, i = 1, n; n = 10; a = b = 1; System.out.print(a+" "+b); while(i<n) { c = a + b; System.out.print(" "); System.out.print(c); a = b; b = c; i++; } } }
Output
1 1 2 3 5 8 13 21 34 55 89
Advertisements