develop #2
@@ -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!
|
||||
*/
|
||||
public char[][] generateTriangle(int n) {
|
||||
|
||||
// todo
|
||||
return null;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user