Reputation: 25
I would like get last index of each row of my grid for replace the "." by "t".
Here is what I have for the moment :
So far I have only managed to do this on one line. I had tried to do it on several lines but it did not work I found myself with an offset of 1 for each line.
My code :
for (int rows = 0; rows < size; rows++) {
for (int columns = 0; columns < size; columns++) {
if (divisibleBy3(rows) && divisibleBy3(columns)) {
builder.append(pos);
}
else if(endArray >= (size*size-1) - size + 1 && endArray <= (size*size) - 1){
if(divisibleBy3(endArray)){
builder.append(pos);
}
else {
builder.append(voidCase);
}
}
else {
builder.append(voidCase);
}
endArray++;
}
if(endRow == size - 1){
builder.setCharAt(endRow, 't');
endRow = 0;
}
endRow++;
builder.append("\n");
}
Thanks for your help.
Upvotes: 0
Views: 113
Reputation: 1343
The problem in your code causing the observed behaviour is, that endArray
has always the same value. Thus you are replacing the char at the same index over and over again. Something like this would probably work as intended:
if (endArray == (rows + 1) * size) {
builder.setCharAt(endArray + rows - 1, 't');
endRow = 0;
} else {
endRow++;
}
Upvotes: 1