zoukankan      html  css  js  c++  java
  • C#用嵌套的 for 循环实现打印图形

    1.题目要求如下:

     2.来吧,展示:

    首先,外层循环应当循环 7 次( 7 行);内层循环也应该循环 7 次(每行 7 列);内层循环后面换行。

    每一个字符输出时,检查是不是处于对角线的位置,如果在对角线上,就输出英文字母“O”,否则输出“.”。

    从左上到右下的对角线的特点是:行数==列数

    从右上到左下的对角线的特点是:行数+列数==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++)//循环7行
                {
                    for (int y = 1; y <= 7; y++)//循环7列
                    {
                        if (x == y || x + y == 8)//对角线打印O
                        {
                            Console.Write("O");
                        }
                        else
                        {
                            Console.Write(".");//其他位置打印.
                        }
                    }
                    Console.WriteLine();//换行
                }
                //请完善代码
                
            }
        }
    }
    

    3.打印结果如下:

    希望能帮到大家,问你们要一个赞,你们会给吗,谢谢大家
    版权声明:本文版权归作者(@攻城狮小关)和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    大家写文都不容易,请尊重劳动成果~
    交流加Q:1909561302
    CSDN地址https://blog.csdn.net/Mumaren6/

  • 相关阅读:
    PAT 甲级 1115 Counting Nodes in a BST (30 分)
    PAT 甲级 1114 Family Property (25 分)
    PAT 甲级 1114 Family Property (25 分)
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
  • 原文地址:https://www.cnblogs.com/guanguan-com/p/13695200.html
Copyright © 2011-2022 走看看