Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/First-Assignment-WarmUp.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/material_theme_project_new.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 38 additions & 5 deletions AP1403 - WarmUp/src/main/java/Exercises.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
Expand All @@ -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;
}

Expand All @@ -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) {
Expand Down