From 717ac7853efc82e2bb8402ed8408749279bccee9 Mon Sep 17 00:00:00 2001 From: James Yoo Date: Tue, 25 Oct 2022 11:06:36 -0700 Subject: Adding AspectJ version of Fibonacci --- entries/jyoo980/aspectj/Fibonacci.aj | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 entries/jyoo980/aspectj/Fibonacci.aj (limited to 'entries') diff --git a/entries/jyoo980/aspectj/Fibonacci.aj b/entries/jyoo980/aspectj/Fibonacci.aj new file mode 100644 index 0000000..39dfd8a --- /dev/null +++ b/entries/jyoo980/aspectj/Fibonacci.aj @@ -0,0 +1,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; + } +} -- cgit v1.2.3-70-g09d2