aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBraxton Hall2022-12-11 00:46:58 +0000
committerGitHub2022-12-11 00:46:58 +0000
commitf7106d5d6291eb9aa3b4b3ec869ab89c9b1612b8 (patch)
tree092e35c364d134f92404f229c5f54e0dcffd9037
parent1eec7f557b37ff0ff814e95c13163a2dc397b467 (diff)
parent9c1a5ce1fd99409dfbdfcba2370fbe07b54f8432 (diff)
Merge pull request #93 from ardier/main
Added Java entry by ardier
-rw-r--r--entries/ardier/java/Main.java23
-rw-r--r--people.json5
2 files changed, 28 insertions, 0 deletions
diff --git a/entries/ardier/java/Main.java b/entries/ardier/java/Main.java
new file mode 100644
index 0000000..554e346
--- /dev/null
+++ b/entries/ardier/java/Main.java
@@ -0,0 +1,23 @@
+import java.util.HashSet;
+
+public class Main {
+ private static HashSet<Integer> BASE_CASE;
+
+ public static void main(String[] args) {
+ BASE_CASE = new HashSet<Integer>();
+ BASE_CASE.add(1);
+ BASE_CASE.add(2);
+
+ for (int i = -20; i < 20; i++) {
+ System.out.println("The fib value for " + i + " is " + fib(i));
+ }
+ }
+
+ private static int fib(int entry) {
+ return entry == 0 ? 0 : ((entry < 0 && entry % 2 == 0) ? -fibHelper(Math.abs(entry)) : fibHelper(Math.abs(entry)));
+ }
+
+ private static int fibHelper(int entry) {
+ return BASE_CASE.contains(entry) ? 1 : fibHelper(entry - 1) + fibHelper(entry - 2);
+ }
+} \ No newline at end of file
diff --git a/people.json b/people.json
index f7f7ae7..897a585 100644
--- a/people.json
+++ b/people.json
@@ -714,7 +714,12 @@
{
"name": "One-liners in Python",
"link": "./entries/ardier/python/main.py"
+ },
+ {
+ "name": "One-liners in Java",
+ "link": "./entries/ardier/java/Main.java"
}
+
]
}
]