aboutsummaryrefslogtreecommitdiff
path: root/entries/jyoo980/aspectj/Fibonacci.aj
blob: 39dfd8a43b33e2985f6763d8ed2b510c3e2668a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public aspect Fibonnacci {

    pointcut mainInvocation(): call(* Main.*(*));

    void before(): mainInvocation() {
        // Nice
        int n = 69;
        System.out.println("The 69th fibonacci number is: " + fibonacci(n));
    }

    public int fibonacci(int n) {
        int prev = 0;
        int curr = 1;
        for (int i = 0; i < n; i++) {
            int tmp = prev;
            prev = curr;
            curr = prev + tmp;
        }
        return prev;
    }
}