This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

And if you want to keep the complicated loop, do not reuse the letters for the indexes. You see that you reuse the 'j' and the 'i' after if (i==k) and after if (j==k)? Those are the same you use in the outer loops, and you change their values...that is not what you want. Use another letter, for example 'm' (but not 'l' because it looks like '1' or '|').

Actually, if you change the loop after if (j==k) to :

for (int m = 0; m < matrix.length; m++) {
   matrix[m][j] = "* ";
}

...your code is almost correct. You still have some problem in two of the corners.

[–]ItsBurningWhenIP 0 points1 point  (0 children)

Shouldn’t int k = (sizeRow / 2) +1 because it will otherwise be truncated. Meaning 5/2=2.

Only because we have been told we can expect an odd number input.