Star triangle with boolean array
Hey guys.
My task is to print out a equal-sided triangle, like this:
____*
___***
__*****
(__ are empty spaces)
I have to use a boolean[][] array. Everytime when a star has to be drawn, true should be returned. If a space character, false should be returned.
Heres my code.
Code:
public class Application {
public static void main(String[] args) {
int eingabe = 3;
int anzahl = eingabe;
boolean[][] matrix = new boolean[eingabe][];
for ( int j = 0; j<matrix.length ; j++ ){
for(int i=0; i<anzahl; i++)
matrix[ j ]= new boolean[ j + eingabe];
}
for ( int i = 0 ; i < matrix.length ; i++ )
{ for ( int j = 0 ; j < matrix[i].length ; j++ )
System.out.print( matrix[i][j] + " " );
System.out.println();
}
I hope someone can help me. Thanks!!
Re: Star triangle with boolean array
Do you have a question?
Does you code compile and execute? What happens?
Copy and post here the output from your code if you are asking for help with your program.
What is the logic for your code? What does it do for each row?
How many spaces and how many *s does it output for each row?
What is the relationship between the row number and the number of spaces and the number of *s
One thing I don't see is the '*' character that is to be printed out.