-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab20.java
More file actions
22 lines (18 loc) · 803 Bytes
/
lab20.java
File metadata and controls
22 lines (18 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.*;
public class lab20 { //Program By pranay Bokde
public static void main(String[] args) {
int n, firstTerm = 0, secondTerm = 1; //assinging value for first and second term
Scanner sc =new Scanner(System.in);
System.out.print("Enter a number till you want fibonacci series: ");
n = sc.nextInt();
//taking input of the number till we want to find the fibonacci series
System.out.println("Fibonacci Series till " + n + " terms:");
for (int i = 1; i <= n; ++i) {
System.out.print(firstTerm + ","); //loop from 1 to n
// compute the next term
int nextTerm = firstTerm + secondTerm;
firstTerm = secondTerm;
secondTerm = nextTerm;
}
}
}