請問我的為什么不對呢?到底哪里邏輯有問題?
for(int i=0;i<7;i++)
{
????for(int j=0;j<7;j++)
????{
????????if(i==j || i+j==8)
????????{
????????????Console.Write("O");
????????}
????????else
????????{
????????????Console.Write(".");
????????}
????}
????Console.WriteLine();
}
2020-07-06
i和j都等于0的話符合if里面i==j的條件會打印出一個O,
然后j經(jīng)過7次循環(huán)最后值為6,此時i=0,j=6不符合i+j==8,輸出"."
所以第一行只會有一個O
第二個外循環(huán)開始時,i=1,j=0第一個位置再輸出"."
問題就出來了
2022-06-14
你既然是從0開始,那么相加應(yīng)該==7,而不是8;
? ? ? ? ? ? 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();
? ? ? ? ? ? }
2021-03-16
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==8 || x-y==0)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Console.Write("o");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Console.Write(".");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Console.WriteLine();
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
樓主可以參考一下我的,希望對你有幫助
2020-08-18
?for(int x=1;x<8;x++)
??????????? {
?????????????? for(int y=1;y<8;y++)
?????????????? {
????????????????? if(y==x||y==(8-x))
????????????????? Console.Write('0');
????????????????? else
???????????????? Console.Write('.');
?????????????? }
?????????????? Console.WriteLine();
??????????????
??????????????
??????????? }
2020-07-06
謝謝熱心解答!