循環嵌套+三元運算符
for (int row = 0; row < 7; row++)?
?{? ? ? ? ? ? ? ?
? ???for (int col = 0; col < 7; col++) ??
? ? ? { ? ? ? ? ? ? ?
??????????Console.Write((row == col | row + col == 6) ? " O " : "."); ?
??????} ?
????? Console.WriteLine(); ? ? ?
? }
for (int row = 0; row < 7; row++)?
?{? ? ? ? ? ? ? ?
? ???for (int col = 0; col < 7; col++) ??
? ? ? { ? ? ? ? ? ? ?
??????????Console.Write((row == col | row + col == 6) ? " O " : "."); ?
??????} ?
????? Console.WriteLine(); ? ? ?
? }
2023-06-07
舉報
2023-06-15
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? //請完善代碼
? ? ? ? ? ? for(int i=0;i<7;i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? for(int j=0;j<7;j++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? // if(j==i||j==6-i)
? ? ? ? ? ? ? ? ? ? // {
? ? ? ? ? ? ? ? ? ? //? ? ?Console.Write("o");
? ? ? ? ? ? ? ? ? ? // }
? ? ? ? ? ? ? ? ? ? // else
? ? ? ? ? ? ? ? ? ? // {
? ? ? ? ? ? ? ? ? ? //? ? ?Console.Write(".");
? ? ? ? ? ? ? ? ? ? // }
? ? ? ? ? ? ? ? ? ? Console.Write((j==i||j==6-i)?"o":".");? ??
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Console.Write("\n");
? ? ? ? ? ? }
? ? ? ? }
? ? }
}