Main Exercise 1 completed.

This commit is contained in:
2026-04-22 15:59:05 +03:30
parent e73ac6115f
commit 2d725cce52
2 changed files with 10 additions and 21 deletions
+9 -20
View File
@@ -1,28 +1,17 @@
public class MainExercises
{
/*
you should create a triangle with "*" and return a two-dimensional array of characters based on that
the triangle's area is empty, which means some characters should be " "
example 1, input = 3:
*
**
***
example 2, input = 5:
*
**
* *
* *
*****
the output has to be a two-dimensional array of characters, so don't just print the triangle!
*/
public char[][] generateTriangle(int n) {
char[][] Triangle = new char[n][];
// todo
return null;
for(int i=0; i<n; i++) {
Triangle[i] = new char[i+1];
for (int j = 0; j <= i; j++) {
if (j == 0 || i == n-1 || i == j) {Triangle[i][j] = '*';}
else {Triangle[i][j] = ' ';}
}
}
return Triangle;
}
+1 -1
View File
@@ -51,4 +51,4 @@ public class MainTestTriangle {
char[][] expected = {};
assertArrayEquals(expected, ex.generateTriangle(0));
}
}
}