Skip to content

Commit e0d3cc0

Browse files
authored
Merge pull request #69 from DushyanthaAT/main
Fibonacci.java
2 parents 0f2f250 + a2208d4 commit e0d3cc0

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

Fibonacci.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
class FibonacciSeries {
2-
public static void main(String args[])
3-
{
4-
int n1=0,n2=1,n3,i,count=10;
5-
6-
//printing 0 and 1
7-
System.out.print(n1+" "+n2);
8-
9-
//loop starts from 2 because 0 and 1 are already printed
10-
for(i=2;i<count;++i) {
11-
n3=n1+n2;
12-
System.out.print(" "+n3);
13-
n1=n2;
14-
n2=n3;
2+
public static void main(String args[])
3+
{
4+
int n1=0,n2=1,n3,i,count;
5+
Scanner scanner=new Scanner(System.in);
6+
System.out.print("Enter a count : ");
7+
count=scanner.nextInt();
8+
9+
10+
//printing 0 and 1
11+
if(count<2){
12+
System.out.print(n1+" "+n2);
13+
}
14+
15+
16+
//loop starts from 2 because 0 and 1 are already printed
17+
for(i=2;i<=count;++i) {
18+
System.out.print(n1+" "+n2);
19+
n3=n1+n2;
20+
System.out.print(" "+n3);
21+
n1=n2;
22+
n2=n3;
23+
}
1524
}
16-
}
1725
}
18-

0 commit comments

Comments
 (0)