for (int x=1;x<=7;x++)
{
for (int y=1;y<=7;y++)
{
if (x==y||x+y==8)
{
Console.Write("O");
}
else
{
Console.Write(".");
}
}
Console.WriteLine();
}
for (int x = 1; x <= 7; x++)//循环7行
{
for (int y = 1; y <= 7; y++)//循环7列
{
if (x == y || x + y == 8)//对角线打印O
{
Console.Write("O");
}
else
{
Console.Write(".");//其他位置打印.
}
}
Console.WriteLine();//换行
}
for(int x=0; x<7; x++) { for(int y=0; y<7; y++) { if(x==y || (x+y)==6) { Console.Write('o'); } else { Console.Write('.'); } } }
if(x==y || x+y==8)里面括号用成中文了
贴上正确的代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
for (int x=1;x<=7;x++)
{
for (int y=1;y<=7;y++)
{
if (x==y||x+y==8)
{
Console.Write("O");
}
else
{
Console.Write(".");
}
}
Console.WriteLine();
}
}
}
}