implement generateTriangle function in MainExercises

This commit is contained in:
2026-04-22 15:17:18 +03:30
parent f77e3bdc26
commit bd386a5eb6
+13 -4
View File
@@ -19,10 +19,19 @@ public class MainExercises
the output has to be a two-dimensional array of characters, so don't just print the triangle! the output has to be a two-dimensional array of characters, so don't just print the triangle!
*/ */
public char[][] generateTriangle(int n) { public char[][] generateTriangle(int n) {
char[][] triangle = new char[n][];
// todo for (int i = 0; i < n; i++) {
return null; 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;
} }