Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7423d44

Browse files
Merge pull request fnplus#217 from vyom153069/patch-1
Fibonacci.java
2 parents 64c6c7f + 1836e60 commit 7423d44

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import java.util.Scanner;
2+
public class Fibonacci {
3+
public static void main(String[] args) {
4+
Scanner sc=new Scanner(System.in);
5+
System.out.print("Enter number of terms: ");
6+
int n=sc.nextInt();
7+
int t1 = 0, t2 = 1;
8+
System.out.print("First " + n + " terms: ");
9+
for (int i = 1; i <= n; ++i)
10+
{
11+
System.out.print(t1 + " + ");
12+
int sum = t1 + t2;
13+
t1 = t2;
14+
t2 = sum;
15+
}
16+
}
17+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /