-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathiz.java
More file actions
36 lines (27 loc) · 653 Bytes
/
iz.java
File metadata and controls
36 lines (27 loc) · 653 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//Write a Program to Display Fibonacci Series upto nth term (n is entered by user)
import java.util.Scanner;
public class Fibonacci {
public static void main(String[] args) {
Scanner sc= new Scanner (System.in);
int n,temp1=0, temp2=1,fact;
System.out.println("Enter value of N");
n =sc.nextInt();
System.out.print("Factorial of "+n+" is : ");
for (int i=1; i<n;i++)
{
if(i==1) {
System.out.print(temp1+" ");
}
if(i==2) {
System.out.print(temp2+" ");
}
fact=temp1+temp2;
temp1=temp2;
temp2=fact;
System.out.print(fact+" ");
}
sc.close();
}
}
#hacktoberfest2021
#hacktober-indonesia