diff --git a/AP1403 - WarmUp/pom.xml b/AP1403 - WarmUp/pom.xml
index 20d027a..6699250 100644
--- a/AP1403 - WarmUp/pom.xml
+++ b/AP1403 - WarmUp/pom.xml
@@ -15,24 +15,31 @@
+
org.junit.jupiter
- junit-jupiter
- 5.11.4
+ junit-jupiter-api
+ 5.9.2
test
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.9.2
+
+
org.apache.maven.plugins
maven-surefire-plugin
- 3.5.2
+ 2.22.2
-
\ No newline at end of file
+
diff --git a/AP1403 - WarmUp/src/main/java/Exercises.class b/AP1403 - WarmUp/src/main/java/Exercises.class
new file mode 100644
index 0000000..fde2003
Binary files /dev/null and b/AP1403 - WarmUp/src/main/java/Exercises.class differ
diff --git a/AP1403 - WarmUp/src/main/java/Exercises.java b/AP1403 - WarmUp/src/main/java/Exercises.java
index 923d44a..4c5a24d 100644
--- a/AP1403 - WarmUp/src/main/java/Exercises.java
+++ b/AP1403 - WarmUp/src/main/java/Exercises.java
@@ -4,8 +4,17 @@ public class Exercises {
complete this function to check if the input number is prime or not
*/
public boolean isPrime(long n) {
- // todo
- return false;
+ if (n <= 1) {
+ return false;
+ }
+
+ for (long i = 2; i * i <= n; i++) {
+ if (n % i == 0) {
+ return false;
+ }
+ }
+
+ return true;
}
/*
@@ -15,8 +24,25 @@ public boolean isPrime(long n) {
if the input is not a fibonacci number with description above, return -1
*/
public long fibonacciIndex(long n) {
- // todo
- return -1;
+ if (n < 0) {
+ return -1;
+ }
+
+ long a = 0, b = 1;
+ long index = 1;
+
+ if (n == 0) {
+ return 0;
+ }
+
+ while (b < n) {
+ long temp = a + b;
+ a = b;
+ b = temp;
+ index++;
+ }
+
+ return (b == n) ? index : -1;
}
/*
@@ -37,12 +63,34 @@ public long fibonacciIndex(long n) {
the output has to be a two-dimensional array of characters, so don't just print the triangle!
*/
+
public char[][] generateTriangle(int n) {
- // todo
- return null;
+
+ char[][] triangle = new char[n][];
+
+
+ for (int i = 0; i < n; i++) {
+ triangle[i] = new char[i + 1];
+
+ for (int j = 0; j <= i; j++) {
+
+ if ((j == 0) || (j == i) || (i == n - 1)) {
+ triangle[i][j] = '*';
+ }
+ else {
+ triangle[i][j] = ' ';
+ }
+ }
+ }
+
+ if (n == 0) {
+ triangle = new char[0][];
+ }
+
+ return triangle;
}
+
public static void main(String[] args) {
- // you can test your code here, but then it should be checked with test cases
}
-}
+}
\ No newline at end of file