implement triangle method
This commit is contained in:
@@ -19,9 +19,20 @@ 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][];
|
||||||
|
for(int i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
triangle[i] = new char[i+1];
|
||||||
|
for(int j = 0; j <= i; j++)
|
||||||
|
{
|
||||||
|
if(i == 0 || j == 0 || i == j || i == n-1)
|
||||||
|
triangle[i][j] = '*';
|
||||||
|
else
|
||||||
|
triangle[i][j] = ' ';
|
||||||
|
}
|
||||||
|
|
||||||
// todo
|
}
|
||||||
return null;
|
return triangle;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user