From 308c5907e878ac6f467a196ff00613cce2cfe344 Mon Sep 17 00:00:00 2001 From: MOOH Date: Fri, 7 Mar 2025 12:06:22 +0330 Subject: [PATCH 1/2] Questions are solved --- AP1403 - WarmUp/src/main/java/Exercises.java | 43 +++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/AP1403 - WarmUp/src/main/java/Exercises.java b/AP1403 - WarmUp/src/main/java/Exercises.java index 923d44a..5ab02a8 100644 --- a/AP1403 - WarmUp/src/main/java/Exercises.java +++ b/AP1403 - WarmUp/src/main/java/Exercises.java @@ -4,8 +4,13 @@ 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 (int i = 2; i <= (n / 2) ; i++) { + if (n % i == 0) { + return false; } + } + return true; } /* @@ -15,7 +20,18 @@ public boolean isPrime(long n) { if the input is not a fibonacci number with description above, return -1 */ public long fibonacciIndex(long n) { - // todo + if (n== 0) return 0; + if (n == 1) return 1; + int a = 0 , b = 1 , c = 1; + int res = 1; + while (c < n ) { + c = a + b; + res++; + a = b; + b = c; + } + if (c == n) return res; + return -1; } @@ -38,8 +54,25 @@ 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; + if (n == 0) { + return new char[0][0]; + } + + 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] = ' '; + } + } + } + + return triangle; } public static void main(String[] args) { From 695b8efeb855b6da0347de390df27d9f3d3d74fe Mon Sep 17 00:00:00 2001 From: MOOH Date: Fri, 7 Mar 2025 23:25:13 +0330 Subject: [PATCH 2/2] solved questions --- .idea/.gitignore | 8 ++++++++ .idea/First-Assignment-WarmUp.iml | 9 +++++++++ .idea/compiler.xml | 13 +++++++++++++ .idea/encodings.xml | 7 +++++++ .idea/jarRepositories.xml | 20 ++++++++++++++++++++ .idea/material_theme_project_new.xml | 12 ++++++++++++ .idea/misc.xml | 14 ++++++++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ 9 files changed, 97 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/First-Assignment-WarmUp.iml create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/material_theme_project_new.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/First-Assignment-WarmUp.iml b/.idea/First-Assignment-WarmUp.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/First-Assignment-WarmUp.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..255d526 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..1c7462a --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..dc06877 --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0f8081f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ca611f1 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file