I'm trying to create a triangle where empty cells have spaces and non empty cells have X's.
public static char[][] Triangle(int size) {
char[][] triangle = new char[size][size];
for (int i = 0; i < size; i++) {
Arrays.fill(triangle[i], '_');
}
for (int rows = 0; rows < size; rows++) {
for (int columns = 0; columns < rows + 1; columns++) {
triangle[rows][columns] = 'T';
}
}
return triangle;
}
Somethings not working though. Not sure what it is? Edit: I found a fix and made the changes above.
Triangle()?size, then include exactly what output you actually got. If you don't include that vital piece of information, you'll get many shotgun answers that may or may not solve your problem.