forked from nitin-jaiman/JavaAlgorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacci.java
More file actions
55 lines (37 loc) · 956 Bytes
/
Fibonacci.java
File metadata and controls
55 lines (37 loc) · 956 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.nitin.jaiman;
/**
*
* @author nitin
*/
public class Fibonacci {
public double fibitteration(int n){
int temp=1;
int b=1;
int result=2;
double start=System.currentTimeMillis();
for(int i=0;i<n;i++){
temp=result;
result=result+b;
b=temp;
}
System.out.println(result);
double end=System.currentTimeMillis();
return end-start;
}
public double executefibrecurrsion(int n){
double start=System.currentTimeMillis();
System.out.println(fibrecurrsion(n));
double end=System.currentTimeMillis();
return end-start;
}
public double fibrecurrsion(int n){
if(n<2){
return 1;
}
return fibrecurrsion(n-1)+fibrecurrsion(n-2);
}
}