Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Fibonacci series program in Java without using recursion.
Following is the required program.
Example
public class Tester {
public static void main(String args[]) {
int n1 = 0, n2 = 1, n3, i, max = 5;
System.out.print(n1 + " " + n2);
for (i = 2; i < max; ++i) {
n3 = n1 + n2;
System.out.print(" " + n3);
n1 = n2;
n2 = n3;
}
}
}
Output
0 1 1 2 3
Advertisements