You'll need two for loops, an outer loop for the rows, an inner loop for the columns. Next, you need a function, that takes a row and column value and calculates from those values whether you have to plot a star or not. The basic alogrithm goes like this (for the stars):
Plotter plotter = new FilledTreePlotter();
for (row = 0; row < maxRows; row++) {
for (column = 0; column < maxColumns; column++ {
System.out.print(plotter.getCellContent(row,column));
}
System.out.print("\n");
}
I've added some OO falvour to the basic algorithm. You'll need an additional interface
public interface Plotter {
public char getCellContent(int row, int column);
}
and now you can implement a class that, for instance, can plot the filled triangle:
public FilledTreePlotter implements Plotter {
public char getCellContent(int row, int column) {
if ( ... ) {
// your magic says, that this is a star
return ('*');
} else {
return (' ');
}
}
}
Here is a demo implementation for another task, which will just plot a diagonal line:
public DiagonalPlotter implements Plotter {
public char getCellContent(int row, int column) {
if ( row == column ) {
return ('*');
} else {
return (' ');
}
}
}