fix generateTriangle method logical bug
This commit is contained in:
@@ -2,10 +2,11 @@ public class MainExercises
|
||||
{
|
||||
public char[][] generateTriangle(int n) {
|
||||
|
||||
char[][] result = new char[n][n];
|
||||
char[][] result = new char[n][];
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
result[i] = new char[i+1];
|
||||
if (i == n-1)
|
||||
{
|
||||
for (int j = 0; j <= i; j++)
|
||||
@@ -17,6 +18,8 @@ public class MainExercises
|
||||
{
|
||||
result[i][0] = '*';
|
||||
result[i][i] = '*';
|
||||
|
||||
for (int j = 1; j < i; j++) result[i][j] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user