Skip to content

Commit

Permalink
Implementation of java algorithm for fibonacci series (#45)
Browse files Browse the repository at this point in the history
Co-authored-by: snehamichelle <[email protected]>
  • Loading branch information
Namslay26 and SnehaMichelle authored Oct 9, 2022
1 parent 9b4decf commit 7bdb17d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Java/Fibonacci.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ public static void main(String[] args) {
static void fib(int n) {
// Fibonacci sequence
// your code here
int num1 = 0;
int num2 = 1;
int num3;
System.out.println(num1); //print 0
System.out.println(num2);//print 1
//start loop from 2
for (int i =2;i<n;i++){
//add the two numbers
num3 = num1+num2;
//print
System.out.println(num3);
//swap the numbers
num1 = num2;
num2=num3;
num3=num1;
}


}

Expand Down

0 comments on commit 7bdb17d

Please sign in to comment.