Assuming your loop indexes are i, j and both go from 0 to 4, the third pattern is X when it's a line with slope=1 (i=j) and also when slope=-1 (i = 4-j, or i+j=4).
So, inside your inner loop, something like:
if ((i == j) || (i == 4 - j)) System.out.print("X");
else System.out.print("O");
@M
McFate · 3 ปีที่ผ่านมา
ความคิดเห็น 0 0
คำตอบ
The key is to figure out the proper condition. If you look at the coordinates of the X's, it's quite simple. In the second pattern, x == y for every X.
The third one adds the other diagonal, and for every X in that, x + y equals 6.
for (int y = 1; y